Skip to content

Commit 813118c

Browse files
committed
Add some system benchmarks.
1 parent eace2fe commit 813118c

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed

benchmark/core/fiber-creation.rb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
puts RUBY_VERSION
2+
3+
3.times do
4+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
5+
6+
fibers = 10000.times.map do
7+
Fiber.new do
8+
end
9+
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+
15+
fibers.each(&:resume)
16+
17+
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
18+
puts "Fiber resume duration: #{duration} seconds"
19+
end

benchmark/core/results.md

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
## Ruby 2.6.10
2+
3+
```
4+
samuel@aiko ~/P/i/benchmarks> ruby fiber-creation.rb
5+
2.6.10
6+
Fiber creation duration: 0.03247421991545707 seconds
7+
Fiber resume duration: 0.033807114930823445 seconds
8+
Fiber creation duration: 0.03336292295716703 seconds
9+
Fiber resume duration: 0.03446975699625909 seconds
10+
Fiber creation duration: 0.036547233001329005 seconds
11+
Fiber resume duration: 0.037760776933282614 seconds
12+
samuel@aiko ~/P/i/benchmarks> ruby thread-creation.rb
13+
2.6.10
14+
Thread creation duration: 0.3327406020835042 seconds
15+
Thread join duration: 0.3362921440275386 seconds
16+
Thread creation duration: 0.28885943605564535 seconds
17+
Thread join duration: 0.3024547479581088 seconds
18+
Thread creation duration: 0.28072248096577823 seconds
19+
Thread join duration: 0.2932344099972397 seconds
20+
```
21+
22+
## Ruby 2.7.7
23+
24+
```
25+
samuel@aiko ~/P/i/benchmarks> ruby fiber-creation.rb
26+
2.7.7
27+
Fiber creation duration: 0.004129973007366061 seconds
28+
Fiber resume duration: 0.009417430032044649 seconds
29+
Fiber creation duration: 0.00369942095130682 seconds
30+
Fiber resume duration: 0.008967867936007679 seconds
31+
Fiber creation duration: 0.0028550089336931705 seconds
32+
Fiber resume duration: 0.00814394501503557 seconds
33+
samuel@aiko ~/P/i/benchmarks> ruby thread-creation.rb
34+
2.7.7
35+
Thread creation duration: 0.14376470306888223 seconds
36+
Thread join duration: 0.15650222299154848 seconds
37+
Thread creation duration: 0.05303007597103715 seconds
38+
Thread join duration: 0.10422574798576534 seconds
39+
Thread creation duration: 0.019414776004850864 seconds
40+
Thread join duration: 0.08457108191214502 seconds
41+
```
42+
43+
## Ruby 3.0.4
44+
45+
```
46+
samuel@aiko ~/P/i/benchmarks> ruby fiber-creation.rb
47+
3.0.4
48+
Fiber creation duration: 0.00412312091793865 seconds
49+
Fiber resume duration: 0.009137733955867589 seconds
50+
Fiber creation duration: 0.003599958959966898 seconds
51+
Fiber resume duration: 0.00864996190648526 seconds
52+
Fiber creation duration: 0.0029245070181787014 seconds
53+
Fiber resume duration: 0.008252070983871818 seconds
54+
samuel@aiko ~/P/i/benchmarks> ruby thread-creation.rb
55+
3.0.4
56+
Thread creation duration: 0.15326495608314872 seconds
57+
Thread join duration: 0.1620923290029168 seconds
58+
Thread creation duration: 0.04059368500020355 seconds
59+
Thread join duration: 0.09797750308644027 seconds
60+
Thread creation duration: 0.026068986975587904 seconds
61+
Thread join duration: 0.08405434701126069 seconds
62+
```
63+
64+
## Ruby 3.1.3
65+
66+
```
67+
samuel@aiko ~/P/i/benchmarks> ruby fiber-creation.rb
68+
3.1.3
69+
Fiber creation duration: 0.00456259201746434 seconds
70+
Fiber resume duration: 0.009786766022443771 seconds
71+
Fiber creation duration: 0.003958209999836981 seconds
72+
Fiber resume duration: 0.009175294078886509 seconds
73+
Fiber creation duration: 0.003569778986275196 seconds
74+
Fiber resume duration: 0.008846142911352217 seconds
75+
samuel@aiko ~/P/i/benchmarks> ruby thread-creation.rb
76+
3.1.3
77+
Thread creation duration: 0.14986835094168782 seconds
78+
Thread join duration: 0.16197327291592956 seconds
79+
Thread creation duration: 0.055374343995936215 seconds
80+
Thread join duration: 0.11033689801115543 seconds
81+
Thread creation duration: 0.02628220897167921 seconds
82+
Thread join duration: 0.08593441394623369 seconds
83+
```
84+
85+
## Ruby 3.2.1
86+
87+
```
88+
samuel@aiko ~/P/i/benchmarks> ruby fiber-creation.rb
89+
3.2.1
90+
Fiber creation duration: 0.005040982039645314 seconds
91+
Fiber resume duration: 0.010302124079316854 seconds
92+
Fiber creation duration: 0.003798560006543994 seconds
93+
Fiber resume duration: 0.009062751894816756 seconds
94+
Fiber creation duration: 0.0030817579245194793 seconds
95+
Fiber resume duration: 0.008363569970242679 seconds
96+
samuel@aiko ~/P/i/benchmarks> ruby thread-creation.rb
97+
3.2.1
98+
Thread creation duration: 0.1543678540037945 seconds
99+
Thread join duration: 0.1661193009931594 seconds
100+
Thread creation duration: 0.05045510292984545 seconds
101+
Thread join duration: 0.1042662620311603 seconds
102+
Thread creation duration: 0.026006213040091097 seconds
103+
Thread join duration: 0.0831627210136503 seconds
104+
```

benchmark/core/thread-creation.rb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
puts RUBY_VERSION
2+
3+
3.times do
4+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
5+
6+
threads = 10000.times.map do
7+
Thread.new do
8+
end
9+
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+
15+
threads.each(&:join)
16+
17+
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
18+
puts "Thread join duration: #{duration} seconds"
19+
end

0 commit comments

Comments
 (0)