Hack Forums
[C#] for loop benchmarking - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] for loop benchmarking (/showthread.php?tid=5857495)



for loop benchmarking - int - Jul 3, 2018

Hello, was just wondering a bit about the best variable to use to iterate through an array.

https://github.com/NullFlex/benchmarking_forloops

I tried ulong, int, and uint.
ulong and uint beat int by a lot.
in smaller arrays, uint and ulong had a major advantage.
In bigger arrays, they had a slight advantage.
What really is the best variable for this job?
Not completely sure if my timing method is accurate though.


RE: for loop benchmarking - Nick (Name) - Jul 3, 2018

Depends on what kind of numbers you’re working with, each integral type allocates a different amount of memory. https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/integral-types-table


RE: for loop benchmarking - int - Jul 3, 2018

(Jul 3, 2018 06:09 PM)Nick (Name) Wrote:  Depends on what kind of numbers you’re working with, each integral type allocates a different amount of memory. https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/integral-types-table

Very nice, I was looking for a table like this.
I saw one for c++ a while ago.


RE: for loop benchmarking - Nick (Name) - Jul 3, 2018

(Jul 3, 2018 07:05 PM)Jukeboxhook Wrote:  Very nice, I was looking for a table like this.
I saw one for c++ a while ago.

I live MSDN, great documentation for just about anything in the .NET Framework.