Skip to content

Instantly share code, notes, and snippets.

@thiagoloureiro
Created January 16, 2018 14:11
Show Gist options
  • Save thiagoloureiro/6f745e41ea83cb90c01d7a08dbc60188 to your computer and use it in GitHub Desktop.
Save thiagoloureiro/6f745e41ea83cb90c01d7a08dbc60188 to your computer and use it in GitHub Desktop.
using BenchmarkDotNet.Attributes;
using System.Collections.Generic;
namespace BenchNET
{
public class Iterate
{
private List<string> lstStr;
private int Counter;
public Iterate()
{
lstStr = new List<string>
{
"String1",
"String2",
"String3",
"String4",
"String5",
"String6",
"String7",
"String8",
"String9",
"String10"
};
}
[Benchmark]
public int List_For()
{
for (int i = 0; i < lstStr.Count; i++)
{
Counter++;
}
return Counter;
}
[Benchmark]
public int List_Foreach()
{
foreach (var item in lstStr)
{
Counter++;
}
return Counter;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment