File tree Expand file tree Collapse file tree 2 files changed +18
-18
lines changed Expand file tree Collapse file tree 2 files changed +18
-18
lines changed Original file line number Diff line number Diff line change 22
333 . 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"
1919end
Original file line number Diff line number Diff line change 22
333 . 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"
1919end
You can’t perform that action at this time.
0 commit comments