Skip to content

Commit

Permalink
Improved progress reporting and memory usage (#16)
Browse files Browse the repository at this point in the history
Improved progress reporting and memory usage
  • Loading branch information
L3tum authored Sep 1, 2019
2 parents 7e41b93 + ef4ab17 commit 71a7da8
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 16 deletions.
13 changes: 11 additions & 2 deletions Benchmarker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static void Main(string[] args)
}
});
#else
options = new Options {Benchmark = "AVX", Threads = 1, Runs = 1};
options = new Options {Benchmark = "BZIP2", Threads = 1, Runs = 1};
#endif
var runner = new BenchmarkRunner(options);

Expand All @@ -57,7 +57,16 @@ private static void Main(string[] args)
}
}, ct.Token);

runner.RunBenchmark();
try
{
runner.RunBenchmark();
}
catch (ArgumentException e)
{
Console.WriteLine(e.Message);

return;
}

progress.Report(1.0d);

Expand Down
15 changes: 11 additions & 4 deletions Benchmarking/Arithmetic/Integer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ internal class Integer : Benchmark
{
// 200 "MB"
private const int LENGTH = 200000000;
private readonly byte[] resultByteArray = new byte[LENGTH];
private readonly int[] resultIntArray = new int[LENGTH];
private readonly long[] resultLongArray = new long[LENGTH];
private readonly short[] resultShortArray = new short[LENGTH];
private byte[] resultByteArray;
private int[] resultIntArray;
private long[] resultLongArray;
private short[] resultShortArray;

private byte randomByte;
private int randomInt;
Expand Down Expand Up @@ -188,6 +188,8 @@ public override void Run()
{
resultLongArray[j] = Math.BigMul(randomInt, randomInt);
}

BenchmarkRunner.ReportProgress();
});
}

Expand Down Expand Up @@ -217,6 +219,11 @@ public override void Initialize()
randomByte = (byte) rand.Next();
randomLong = (long) int.MaxValue + rand.Next();
randomShort = (short) rand.Next();

resultByteArray = new byte[LENGTH];
resultIntArray = new int[LENGTH];
resultLongArray = new long[LENGTH];
resultShortArray = new short[LENGTH];
}
}
}
5 changes: 0 additions & 5 deletions Benchmarking/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,5 @@ public virtual double GetReferenceValue()
{
return 0.0d;
}

public virtual void PostRun()
{
BenchmarkRunner.ReportProgress();
}
}
}
2 changes: 2 additions & 0 deletions Benchmarking/Compression/BZip2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public override void Run()
}
}
}

BenchmarkRunner.ReportProgress();
});
}

Expand Down
2 changes: 2 additions & 0 deletions Benchmarking/Compression/Deflate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public override void Run()
}
}
}

BenchmarkRunner.ReportProgress();
});
}

Expand Down
2 changes: 2 additions & 0 deletions Benchmarking/Compression/GZip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public override void Run()
}
}
}

BenchmarkRunner.ReportProgress();
});
}

Expand Down
2 changes: 2 additions & 0 deletions Benchmarking/Compression/ZIP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public override void Run()
}
}
}

BenchmarkRunner.ReportProgress();
});
}

Expand Down
11 changes: 6 additions & 5 deletions Benchmarking/Extension/AVX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;

#if NETCOREAPP3_0
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;

#endif

#endregion
Expand Down Expand Up @@ -44,12 +42,14 @@ public override void Run()
var randomFloatingSpan = new Span<float>(new[] {randomFloatingNumber});
var dst = new Span<float>(datas[i1]);

int iterations = 1000000000 / options.Threads;
var iterations = 1000000000 / options.Threads;

for (var j = 0; j < iterations; j++)
{
AddScalarU(randomFloatingSpan, dst);
}

BenchmarkRunner.ReportProgress();
});
}

Expand Down Expand Up @@ -120,6 +120,7 @@ private unsafe void AssignScalarU(Span<float> scalar, Span<float> dst)
}
}
}

private unsafe void AddScalarU(Span<float> scalar, Span<float> dst)
{
fixed (float* pdst = dst)
Expand Down Expand Up @@ -162,4 +163,4 @@ private unsafe void AddScalarU(Span<float> scalar, Span<float> dst)
}
#endif
}
}
}

0 comments on commit 71a7da8

Please sign in to comment.