File tree 2 files changed +18
-18
lines changed
2 files changed +18
-18
lines changed Original file line number Diff line number Diff line change 2
2
3
3
3 . times do
4
4
start_time = Process . clock_gettime ( Process ::CLOCK_MONOTONIC )
5
-
6
- fibers = 10000 . times . map do
5
+
6
+ fibers = 20_000 . times . map do
7
7
Fiber . new do
8
+ true
8
9
end
9
10
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
+
15
12
fibers . each ( &:resume )
16
-
13
+
17
14
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"
19
19
end
Original file line number Diff line number Diff line change 2
2
3
3
3 . times do
4
4
start_time = Process . clock_gettime ( Process ::CLOCK_MONOTONIC )
5
-
6
- threads = 10000 . times . map do
5
+
6
+ threads = 20_000 . times . map do
7
7
Thread . new do
8
+ true
8
9
end
9
10
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
+
15
12
threads . each ( &:join )
16
-
13
+
17
14
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"
19
19
end
You can’t perform that action at this time.
0 commit comments