StaticFieldProgram -> ArrayIterationProgram

This commit is contained in:
Andrey Akinshin 2013-08-29 14:38:40 +07:00
Родитель 9d57e694cf
Коммит 7cca7715b9
3 изменённых файлов: 24 добавлений и 4 удалений

Просмотреть файл

@ -2,9 +2,9 @@
namespace Benchmarks
{
public class StaticFieldProgram
public class ArrayIterationProgram
{
private const int N = 1000, IterationCount = 1000000;
private const int NUnroll = 1000, N = 1001, IterationCount = 1000000;
private int[] nonStaticField;
private static int[] staticField;
@ -14,11 +14,31 @@ namespace Benchmarks
nonStaticField = staticField = new int[N];
var competition = new BenchmarkCompetition();
competition.AddTask("Non-static/unroll", () => NonStaticUnrollRun());
competition.AddTask("Static/unroll", () => StaticUnrollRun());
competition.AddTask("Non-static", () => NonStaticRun());
competition.AddTask("Static", () => StaticRun());
competition.Run();
}
private int NonStaticUnrollRun()
{
int sum = 0;
for (int iteration = 0; iteration < IterationCount; iteration++)
for (int i = 0; i < NUnroll; i++)
sum += nonStaticField[i];
return sum;
}
private int StaticUnrollRun()
{
int sum = 0;
for (int iteration = 0; iteration < IterationCount; iteration++)
for (int i = 0; i < NUnroll; i++)
sum += staticField[i];
return sum;
}
private int NonStaticRun()
{
int sum = 0;

Просмотреть файл

@ -48,7 +48,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ShiftVsMultiplyProgram.cs" />
<Compile Include="ReverseSortProgram.cs" />
<Compile Include="StaticFieldProgram.cs" />
<Compile Include="ArrayIterationProgram.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BenchmarkDotNet\BenchmarkDotNet.csproj">

Просмотреть файл

@ -12,7 +12,7 @@ namespace Benchmarks
{
new ProgramRunner("Increment", () => new IncrementProgram().Run()),
new ProgramRunner("MultidimensionalArray", () => new MultidimensionalArrayProgram().Run()),
new ProgramRunner("StaticField", () => new StaticFieldProgram().Run()),
new ProgramRunner("ArrayIteration", () => new ArrayIterationProgram().Run()),
new ProgramRunner("ShiftVsMultiply", () => new ShiftVsMultiplyProgram().Run()),
new ProgramRunner("ReverseSort", () => new ReverseSortProgram().Run()),
new ProgramRunner("MakeRefVsBoxing", () => new MakeRefVsBoxingProgram().Run()),