{"id":213,"date":"2022-03-12T14:25:18","date_gmt":"2022-03-12T14:25:18","guid":{"rendered":"https:\/\/baldsolutions.com\/?p=213"},"modified":"2022-03-12T14:37:12","modified_gmt":"2022-03-12T14:37:12","slug":"for-vs-foreach-performance-difference","status":"publish","type":"post","link":"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/","title":{"rendered":"For vs Foreach &#8211; performance difference"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Introduction<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Iterating through collections is part and parcel of programming. As a C# developer you&#8217;ve probably used <code>for<\/code> and <code>foreach<\/code>.  Both helps to iterate through a collection, but it&#8217;s worth to be aware that there are ins and outs. In this post I will show and explain performance differences between iterating through an array and a list using <code>for<\/code> and <code>foreach<\/code>.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Performance<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s consider the following code snippet:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class CollectionsHolder\r\n{\r\n    private readonly List&lt;int> _list;\r\n    private readonly int&#91;] _array;\r\n\r\n    public CollectionsHolder(int count)\r\n    {\r\n        _list = new List&lt;int>(Enumerable.Range(0, count));\r\n        _array = new int&#91;count];\r\n    }\r\n\r\n    public void ForLoopList()\r\n    {\r\n        for (int i = 0; i &lt; _list.Count; i++) { }\r\n    }\r\n\r\n    public void ForeachLoopList()\r\n    {\r\n        foreach (var item in _list) { }\r\n    }\r\n\r\n    public void ForLoopArray()\r\n    {\r\n        for (int i = 0; i &lt; _array.Length; i++) { }\r\n    }\r\n\r\n    public void ForeachLoopArray()\r\n    {\r\n        foreach (var item in _array) { }\r\n    }\r\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>CollectionsHolder<\/code> class stores two collections: <code>_list <\/code>and <code>_array<\/code>. There are four methods that do nothing but iterate through a particular collection &#8211; pretty useless but good enough in terms of benchmarking.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Benchmark (1_000_000_000 elements per collection) results for these four methods stand as follows:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"423\" height=\"160\" src=\"https:\/\/baldsolutions.com\/wp-content\/uploads\/2022\/03\/image.png\" alt=\"\" class=\"wp-image-216\" srcset=\"https:\/\/baldsolutions.com\/wp-content\/uploads\/2022\/03\/image.png 423w, https:\/\/baldsolutions.com\/wp-content\/uploads\/2022\/03\/image-300x113.png 300w\" sizes=\"auto, (max-width: 423px) 100vw, 423px\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">It turns out that <code>foreach<\/code> iteration time is ~7 times slower than using classic <code>for<\/code> when it comes to the list iteration. Surprisingly, <code>foreach<\/code> iteration through the array lasts the same as using <code>for<\/code> loop.  The question is, why <code>ForLoopList<\/code>, <code>ForLoopArray <\/code>and <code>ForeachLoopArray<\/code> last the same, meanwhile <code>ForeachLoopList<\/code> lasts much longer?<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Explanation<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">To get immediate insight I strongly recommend to visit the <a href=\"https:\/\/sharplab.io\/\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"sharplab.io\">sharplab.io<\/a> website. Long story short, the sharplab.io can be used e.g. to see the C# (without syntactic sugar), IL or ASM translation of the C# code (F#, Visual Basic and IL as well at the time of writing the post).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once you&#8217;re there just paste the aforementioned code snippet and focus on the right side:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"949\" height=\"910\" src=\"https:\/\/baldsolutions.com\/wp-content\/uploads\/2022\/03\/image-4.png\" alt=\"\" class=\"wp-image-232\" srcset=\"https:\/\/baldsolutions.com\/wp-content\/uploads\/2022\/03\/image-4.png 949w, https:\/\/baldsolutions.com\/wp-content\/uploads\/2022\/03\/image-4-300x288.png 300w, https:\/\/baldsolutions.com\/wp-content\/uploads\/2022\/03\/image-4-768x736.png 768w\" sizes=\"auto, (max-width: 949px) 100vw, 949px\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see the code from the left side has been translated into the code on the right side (no syntactic sugar). The mystery seems to be solved! The <code>ForLoopList<\/code>, <code>ForLoopArray <\/code>and <code>ForeachLoopArray<\/code> methods have been translated into straightforward <code>while<\/code> loop, hence the execution time of the methods are almost the same (~330ms in our benchmark).  However, the <code>ForeachLoopList<\/code> looks slightly more complicated. These additional lines of code, i.e. getting enumerator ( <code>_list.GetEnumerator()<\/code>), using <code>enumerator.MoveNext()<\/code> and so on, cause additional overhead in terms of the method execution time. <\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Summary<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">In conclusion, <code>for<\/code> and <code>foreach<\/code>, despite the similar usage, might perform differently in terms of time execution. Having that in mind you might think, that you should use <code>for<\/code> any time, but don&#8217;t be fooled. There is something called &#8220;premature optimization&#8221; &#8211; it is a tendency to spend to much time to optimize unnecessary things. Don&#8217;t get me wrong, optimization is crucial, but you should always take into consideration if it is reasonable. Moreover, using <code>foreach<\/code> has its pros, e.g. using it against a list is (in my opinion) much more readable. Readability is sometimes undervalued. Poorly written code is hard to understand, therefore its maintenance is more expensive. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As always I&#8217;ve prepared an example and you can find it on my <a href=\"https:\/\/github.com\/tglowka\/baldsolutions\/tree\/master\/.NET\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"github\">github<\/a>, project: <a href=\"https:\/\/github.com\/tglowka\/baldsolutions\/tree\/master\/.NET\/for-vs-foreach\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><a href=\"https:\/\/github.com\/tglowka\/baldsolutions\/tree\/master\/.NET\/for-vs-foreach\">for-vs-foreach<\/a>, benchmark project: <a href=\"https:\/\/github.com\/tglowka\/baldsolutions\/tree\/master\/.NET\/for-vs-foreach-benchmark\" target=\"_blank\" rel=\"noreferrer noopener\"><a href=\"https:\/\/github.com\/tglowka\/baldsolutions\/tree\/master\/.NET\/for-vs-foreach-benchmark\">for-vs-foreach-benchmark<\/a><\/a>. I encourage you to go through the code, debug it and try to test your own scenarios.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Have a nice day, bye!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Iterating through collections is part and parcel of programming. As a C# developer you&#8217;ve probably used for and foreach. Both helps to iterate through&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/\">Continue reading<span class=\"screen-reader-text\">For vs Foreach &#8211; performance difference<\/span><\/a><\/div>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-213","post","type-post","status-publish","format-standard","hentry","category-net","entry"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Introduction Iterating through collections is part and parcel of programming. As a C# developer you&#039;ve probably used for and foreach. Both helps to iterate through a collection, but it&#039;s worth to be aware that there are ins and outs. In this post I will show and explain performance differences between iterating through an array and\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Tomasz\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Bald Solutions -\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"For vs Foreach \u2013 performance difference - Bald Solutions\" \/>\n\t\t<meta property=\"og:description\" content=\"Introduction Iterating through collections is part and parcel of programming. As a C# developer you&#039;ve probably used for and foreach. Both helps to iterate through a collection, but it&#039;s worth to be aware that there are ins and outs. In this post I will show and explain performance differences between iterating through an array and\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2022-03-12T14:25:18+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2022-03-12T14:37:12+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"For vs Foreach \u2013 performance difference - Bald Solutions\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Introduction Iterating through collections is part and parcel of programming. As a C# developer you&#039;ve probably used for and foreach. Both helps to iterate through a collection, but it&#039;s worth to be aware that there are ins and outs. In this post I will show and explain performance differences between iterating through an array and\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/03\\\/12\\\/for-vs-foreach-performance-difference\\\/#blogposting\",\"name\":\"For vs Foreach \\u2013 performance difference - Bald Solutions\",\"headline\":\"For vs Foreach &#8211; performance difference\",\"author\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/author\\\/tomasz3396\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/baldsolutions.com\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/image.png\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/03\\\/12\\\/for-vs-foreach-performance-difference\\\/#articleImage\",\"width\":423,\"height\":160},\"datePublished\":\"2022-03-12T14:25:18+00:00\",\"dateModified\":\"2022-03-12T14:37:12+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/03\\\/12\\\/for-vs-foreach-performance-difference\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/03\\\/12\\\/for-vs-foreach-performance-difference\\\/#webpage\"},\"articleSection\":\".NET\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/03\\\/12\\\/for-vs-foreach-performance-difference\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/baldsolutions.com\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/category\\\/net\\\/#listItem\",\"name\":\".NET\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/category\\\/net\\\/#listItem\",\"position\":2,\"name\":\".NET\",\"item\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/category\\\/net\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/03\\\/12\\\/for-vs-foreach-performance-difference\\\/#listItem\",\"name\":\"For vs Foreach &#8211; performance difference\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/03\\\/12\\\/for-vs-foreach-performance-difference\\\/#listItem\",\"position\":3,\"name\":\"For vs Foreach &#8211; performance difference\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/category\\\/net\\\/#listItem\",\"name\":\".NET\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/#organization\",\"name\":\"Bald Solutions\",\"url\":\"https:\\\/\\\/baldsolutions.com\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/author\\\/tomasz3396\\\/#author\",\"url\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/author\\\/tomasz3396\\\/\",\"name\":\"Tomasz\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/03\\\/12\\\/for-vs-foreach-performance-difference\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d72f2f7f389921b820e5ef7c2880172fc2b9ae47698a933356df224581de0cc7?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Tomasz\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/03\\\/12\\\/for-vs-foreach-performance-difference\\\/#webpage\",\"url\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/03\\\/12\\\/for-vs-foreach-performance-difference\\\/\",\"name\":\"For vs Foreach \\u2013 performance difference - Bald Solutions\",\"description\":\"Introduction Iterating through collections is part and parcel of programming. As a C# developer you've probably used for and foreach. Both helps to iterate through a collection, but it's worth to be aware that there are ins and outs. In this post I will show and explain performance differences between iterating through an array and\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/2022\\\/03\\\/12\\\/for-vs-foreach-performance-difference\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/author\\\/tomasz3396\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/index.php\\\/author\\\/tomasz3396\\\/#author\"},\"datePublished\":\"2022-03-12T14:25:18+00:00\",\"dateModified\":\"2022-03-12T14:37:12+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/#website\",\"url\":\"https:\\\/\\\/baldsolutions.com\\\/\",\"name\":\"Bald Solutions\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/baldsolutions.com\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"For vs Foreach \u2013 performance difference - Bald Solutions","description":"Introduction Iterating through collections is part and parcel of programming. As a C# developer you've probably used for and foreach. Both helps to iterate through a collection, but it's worth to be aware that there are ins and outs. In this post I will show and explain performance differences between iterating through an array and","canonical_url":"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/#blogposting","name":"For vs Foreach \u2013 performance difference - Bald Solutions","headline":"For vs Foreach &#8211; performance difference","author":{"@id":"https:\/\/baldsolutions.com\/index.php\/author\/tomasz3396\/#author"},"publisher":{"@id":"https:\/\/baldsolutions.com\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/baldsolutions.com\/wp-content\/uploads\/2022\/03\/image.png","@id":"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/#articleImage","width":423,"height":160},"datePublished":"2022-03-12T14:25:18+00:00","dateModified":"2022-03-12T14:37:12+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/#webpage"},"isPartOf":{"@id":"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/#webpage"},"articleSection":".NET"},{"@type":"BreadcrumbList","@id":"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/baldsolutions.com#listItem","position":1,"name":"Home","item":"https:\/\/baldsolutions.com","nextItem":{"@type":"ListItem","@id":"https:\/\/baldsolutions.com\/index.php\/category\/net\/#listItem","name":".NET"}},{"@type":"ListItem","@id":"https:\/\/baldsolutions.com\/index.php\/category\/net\/#listItem","position":2,"name":".NET","item":"https:\/\/baldsolutions.com\/index.php\/category\/net\/","nextItem":{"@type":"ListItem","@id":"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/#listItem","name":"For vs Foreach &#8211; performance difference"},"previousItem":{"@type":"ListItem","@id":"https:\/\/baldsolutions.com#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/#listItem","position":3,"name":"For vs Foreach &#8211; performance difference","previousItem":{"@type":"ListItem","@id":"https:\/\/baldsolutions.com\/index.php\/category\/net\/#listItem","name":".NET"}}]},{"@type":"Organization","@id":"https:\/\/baldsolutions.com\/#organization","name":"Bald Solutions","url":"https:\/\/baldsolutions.com\/"},{"@type":"Person","@id":"https:\/\/baldsolutions.com\/index.php\/author\/tomasz3396\/#author","url":"https:\/\/baldsolutions.com\/index.php\/author\/tomasz3396\/","name":"Tomasz","image":{"@type":"ImageObject","@id":"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/d72f2f7f389921b820e5ef7c2880172fc2b9ae47698a933356df224581de0cc7?s=96&d=mm&r=g","width":96,"height":96,"caption":"Tomasz"}},{"@type":"WebPage","@id":"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/#webpage","url":"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/","name":"For vs Foreach \u2013 performance difference - Bald Solutions","description":"Introduction Iterating through collections is part and parcel of programming. As a C# developer you've probably used for and foreach. Both helps to iterate through a collection, but it's worth to be aware that there are ins and outs. In this post I will show and explain performance differences between iterating through an array and","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/baldsolutions.com\/#website"},"breadcrumb":{"@id":"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/#breadcrumblist"},"author":{"@id":"https:\/\/baldsolutions.com\/index.php\/author\/tomasz3396\/#author"},"creator":{"@id":"https:\/\/baldsolutions.com\/index.php\/author\/tomasz3396\/#author"},"datePublished":"2022-03-12T14:25:18+00:00","dateModified":"2022-03-12T14:37:12+00:00"},{"@type":"WebSite","@id":"https:\/\/baldsolutions.com\/#website","url":"https:\/\/baldsolutions.com\/","name":"Bald Solutions","inLanguage":"en-US","publisher":{"@id":"https:\/\/baldsolutions.com\/#organization"}}]},"og:locale":"en_US","og:site_name":"Bald Solutions -","og:type":"article","og:title":"For vs Foreach \u2013 performance difference - Bald Solutions","og:description":"Introduction Iterating through collections is part and parcel of programming. As a C# developer you've probably used for and foreach. Both helps to iterate through a collection, but it's worth to be aware that there are ins and outs. In this post I will show and explain performance differences between iterating through an array and","og:url":"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/","article:published_time":"2022-03-12T14:25:18+00:00","article:modified_time":"2022-03-12T14:37:12+00:00","twitter:card":"summary","twitter:title":"For vs Foreach \u2013 performance difference - Bald Solutions","twitter:description":"Introduction Iterating through collections is part and parcel of programming. As a C# developer you've probably used for and foreach. Both helps to iterate through a collection, but it's worth to be aware that there are ins and outs. In this post I will show and explain performance differences between iterating through an array and"},"aioseo_meta_data":{"post_id":"213","title":"#post_title #separator_sa #site_title","description":"#post_excerpt","keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[],"defaultGraph":"Article","defaultPostTypeGraph":""},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2022-03-12 12:23:14","updated":"2025-06-04 04:18:05","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/baldsolutions.com\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/baldsolutions.com\/index.php\/category\/net\/\" title=\".NET\">.NET<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tFor vs Foreach \u2013 performance difference\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/baldsolutions.com"},{"label":".NET","link":"https:\/\/baldsolutions.com\/index.php\/category\/net\/"},{"label":"For vs Foreach &#8211; performance difference","link":"https:\/\/baldsolutions.com\/index.php\/2022\/03\/12\/for-vs-foreach-performance-difference\/"}],"_links":{"self":[{"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/comments?post=213"}],"version-history":[{"count":26,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/213\/revisions"}],"predecessor-version":[{"id":244,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/213\/revisions\/244"}],"wp:attachment":[{"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/media?parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/categories?post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/tags?post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}