private static void Benchmark(string comment, Mat @in, Option opt) { @in.Fill(0.01f); using var net = new Net(); net.Opt = opt; if (Ncnn.IsSupportVulkan) { if (net.Opt.UseVulkanCompute) { net.SetVulkanDevice(g_vkdev); } } net.LoadParam($"{comment}.param"); using var dr = new DataReaderFromEmpty(); net.LoadModel(dr); g_blob_pool_allocator.Clear(); g_workspace_pool_allocator.Clear(); if (net.Opt.UseVulkanCompute) { g_blob_vkallocator.Clear(); g_staging_vkallocator.Clear(); } Thread.Sleep(10 * 1000); using var @out = new Mat(); // warm up for (var i = 0; i < g_warmup_loop_count; i++) { using var ex = net.CreateExtractor(); ex.Input("data", @in); ex.Extract("output", @out); } var timeMin = double.MaxValue; var timeMax = -double.MaxValue; var timeAvg = 0d; for (var i = 0; i < g_loop_count; i++) { double start = Ncnn.GetCurrentTime(); { using var ex = net.CreateExtractor(); ex.Input("data", @in); ex.Extract("output", @out); } double end = Ncnn.GetCurrentTime(); var time = end - start; timeMin = Math.Min(timeMin, time); timeMax = Math.Max(timeMax, time); timeAvg += time; } timeAvg /= g_loop_count; var com = comment.PadLeft(20, ' '); var min = $"{timeMin:F2}".PadLeft(7, ' '); var max = $"{timeMax:F2}".PadLeft(7, ' '); var avg = $"{timeAvg:F2}".PadLeft(7, ' '); Console.WriteLine($"{com} min = {min} max = {max} avg = {avg}"); }