Performance Analysis of Loops in the C# Programming Language




Abstract:
This paper presents an experimental evaluation of loop performance characteristics. The paper suggests methods for improving performance beyond pre-optimisation levels, with an emphasis on execution efficiency for collections of reference-type objects. Unlike prior studies that predominantly focus on primitive data types, this work addresses a more representative use case for more complex reference types. An experimental evaluation was carried out using the BenchmarkDotNet NuGet package for Visual Studio to measure loop execution speeds for for, while, and do-while loops while iterating through arrays and generic lists. Two widely adopted optimisation techniques—caching of invariant expressions and loop unrolling—were applied and assessed against non-optimised baseline implementations of the same loops. The experimental setup included datasets of varying sizes, specifically 10,000 and 10,001 elements, to evaluate the impact of remainder handling in loop unrolling. The results indicate that the optimisation techniques provide performance improvements of up to approximately 10%, depending on the loop construct and underlying data structure. For loops demonstrated the most significant performance increases when iterating over arrays, and while loops achieved competitive results in a couple of scenarios involving generic lists. These findings enhance the understanding of loop-level performance optimisation in C#, offering actionable insights for designing performance-critical components in DotNet-based applications. The key contributions of this paper are: • A comparative experiment on loop constructs for reference type collections in C#. • A quantitative assessment of manual optimisation strategies, such as caching and loop unrolling. • An examination of how performance is affected by dataset size and remainder handling.

CITATION:

IEEE format

M. Blagojević, M. Veinović, “Performance Analysis of Loops in the C# Programming Language,” in Sinteza 2026 - International Scientific Conference on Information Technology, Computer Science, and Data Science, Belgrade, Singidunum University, Serbia, 2026, pp. 322-328. doi:10.15308/Sinteza-2026-322-328

APA format

Blagojević, M., Veinović, M. (2026). Performance Analysis of Loops in the C# Programming Language. Paper presented at Sinteza 2026 - International Scientific Conference on Information Technology, Computer Science, and Data Science. doi:10.15308/Sinteza-2026-322-328

BibTeX format
Download

RefWorks Tagged format
Download