Switched benchmark sample to BenchmarkDotNet

このコミットが含まれているのは:
Sergio Pedri committed 2019-08-31 12:48:37 +02:00
1 親 e5aef8b514
コミット 7ca671d9b1
4ファイル変更
+53 -116

検索条件に一致するファイルはありません

+10 -57
ファイルの表示
@@ -1,65 +1,18 @@
using System;
using System.Diagnostics;
using BenchmarkDotNet.Running;
namespace ComputeSharp.Benchmark
{
class Program
public class Program
{
static void Main()
public static void Main()
{
using var benchmark = new FullyConnectedLayerBenchmark();
Console.WriteLine("======== WARMUP ========");
if (!benchmark.EnsureImplementationsMatch()) throw new InvalidOperationException("CPU and GPU code don't match");
Console.WriteLine();
Console.WriteLine("======== GPU with temporary buffer ========");
Stopwatch timer = Stopwatch.StartNew();
TimeSpan cpuTime = TimeSpan.Zero, gpuTime = TimeSpan.Zero;
// GPU with temporary buffers
for (int i = 0; i < 10; i++)
{
benchmark.Cpu();
cpuTime += timer.Elapsed;
Console.WriteLine($"CPU: {timer.Elapsed:g}");
timer.Restart();
benchmark.GpuWithTemporaryBuffers();
gpuTime += timer.Elapsed;
Console.WriteLine($"GPU: {timer.Elapsed:g}");
timer.Restart();
}
Console.WriteLine();
Console.WriteLine("======== AVERAGE ========");
Console.WriteLine($"CPU: {cpuTime / 10:g}");
Console.WriteLine($"GPU: {gpuTime / 10:g}");
Console.WriteLine("=========================");
Console.WriteLine();
Console.WriteLine("======== GPU with no temporary buffer ========");
timer = Stopwatch.StartNew();
cpuTime = gpuTime = TimeSpan.Zero;
// GPU with no temporary buffers
for (int i = 0; i < 10; i++)
{
benchmark.Cpu();
cpuTime += timer.Elapsed;
Console.WriteLine($"CPU: {timer.Elapsed:g}");
timer.Restart();
benchmark.GpuWithNoTemporaryBuffers();
gpuTime += timer.Elapsed;
Console.WriteLine($"GPU: {timer.Elapsed:g}");
timer.Restart();
}
Console.WriteLine();
Console.WriteLine("======== AVERAGE ========");
Console.WriteLine($"CPU: {cpuTime / 10:g}");
Console.WriteLine($"GPU: {gpuTime / 10:g}");
/* =================
* BenchmarkDotNet
* ================
* In order to run this benchmark, compile this project in Release mode,
* then go to its bin\Release\netcoreapp3.0 folder, open a cmd prompt
* and type "dotnet ComputeSharp.Benchmark.dll */
BenchmarkRunner.Run<DnnBenchmark>();
}
}
}