From ab9d5944dcbec87640f9f08cf8800f5cbe41c580 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 17 Aug 2019 22:33:19 +0200 Subject: [PATCH] Updated benchmark code --- samples/ComputeSharp.Benchmark/Program.cs | 37 +++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/samples/ComputeSharp.Benchmark/Program.cs b/samples/ComputeSharp.Benchmark/Program.cs index b6bae6ec..ff22b341 100644 --- a/samples/ComputeSharp.Benchmark/Program.cs +++ b/samples/ComputeSharp.Benchmark/Program.cs @@ -7,12 +7,17 @@ namespace ComputeSharp.Benchmark { static void Main() { - var benchmark = new FullyConnectedLayerBenchmark(); - benchmark.Gpu(); // Warmup + using var benchmark = new FullyConnectedLayerBenchmark(); + Console.WriteLine("======== WARMUP ========"); + benchmark.GpuWithNoTemporaryBuffers(); // Warmup + + 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(); @@ -20,12 +25,38 @@ namespace ComputeSharp.Benchmark Console.WriteLine($"CPU: {timer.Elapsed:g}"); timer.Restart(); - benchmark.Gpu(); + 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}");