Created
January 16, 2018 14:11
-
-
Save thiagoloureiro/6f745e41ea83cb90c01d7a08dbc60188 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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