Skip to content

Commit 46ad298

Browse files
committed
Update benchmarks to output normalised unit time.
1 parent 813118c commit 46ad298

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

benchmark/core/fiber-creation.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
3.times do
44
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
5-
6-
fibers = 10000.times.map do
5+
6+
fibers = 20_000.times.map do
77
Fiber.new do
8+
true
89
end
910
end
10-
11-
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
12-
puts "Fiber creation duration: #{duration} seconds"
13-
# start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
14-
11+
1512
fibers.each(&:resume)
16-
13+
1714
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
18-
puts "Fiber resume duration: #{duration} seconds"
15+
duration_us = duration * 1_000_000
16+
duration_per_iteration = duration_us / fibers.size
17+
18+
puts "Fiber duration: #{duration_per_iteration.round(2)}us"
1919
end

benchmark/core/thread-creation.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
3.times do
44
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
5-
6-
threads = 10000.times.map do
5+
6+
threads = 20_000.times.map do
77
Thread.new do
8+
true
89
end
910
end
10-
11-
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
12-
puts "Thread creation duration: #{duration} seconds"
13-
# start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
14-
11+
1512
threads.each(&:join)
16-
13+
1714
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
18-
puts "Thread join duration: #{duration} seconds"
15+
duration_us = duration * 1_000_000
16+
duration_per_iteration = duration_us / threads.size
17+
18+
puts "Thread duration: #{duration_per_iteration.round(2)}us"
1919
end

0 commit comments

Comments
 (0)