Skip to content

Commit

Permalink
Update benchmarks to output normalised unit time.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Feb 12, 2023
1 parent 813118c commit 46ad298
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions benchmark/core/fiber-creation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 9 additions & 9 deletions benchmark/core/thread-creation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 46ad298

Please sign in to comment.