From 46ad2983fbf9e0bd97f48684cbb7d4407711d49d Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Sun, 12 Feb 2023 19:12:17 +1300 Subject: [PATCH] Update benchmarks to output normalised unit time. --- benchmark/core/fiber-creation.rb | 18 +++++++++--------- benchmark/core/thread-creation.rb | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/benchmark/core/fiber-creation.rb b/benchmark/core/fiber-creation.rb index 5b299f19..f6d0b343 100644 --- a/benchmark/core/fiber-creation.rb +++ b/benchmark/core/fiber-creation.rb @@ -2,18 +2,18 @@ 3.times do start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - - fibers = 10000.times.map do + + fibers = 20_000.times.map do Fiber.new do + true end end - - duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time - puts "Fiber creation duration: #{duration} seconds" - # start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - + fibers.each(&:resume) - + duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time - puts "Fiber resume duration: #{duration} seconds" + duration_us = duration * 1_000_000 + duration_per_iteration = duration_us / fibers.size + + puts "Fiber duration: #{duration_per_iteration.round(2)}us" end diff --git a/benchmark/core/thread-creation.rb b/benchmark/core/thread-creation.rb index 4213c8f6..e52f508b 100644 --- a/benchmark/core/thread-creation.rb +++ b/benchmark/core/thread-creation.rb @@ -2,18 +2,18 @@ 3.times do start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - - threads = 10000.times.map do + + threads = 20_000.times.map do Thread.new do + true end end - - duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time - puts "Thread creation duration: #{duration} seconds" - # start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - + threads.each(&:join) - + duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time - puts "Thread join duration: #{duration} seconds" + duration_us = duration * 1_000_000 + duration_per_iteration = duration_us / threads.size + + puts "Thread duration: #{duration_per_iteration.round(2)}us" end