File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -171,6 +171,10 @@ attr_accessor:
171171 category : micro
172172 single_file : true
173173 ractor : true
174+ block_methods :
175+ desc : calls a handful of builtin Ruby methods that take blocks.
176+ category : micro
177+ single_file : true
174178cfunc_itself :
175179 desc : cfunc_itself just calls the 'itself' method many, many times.
176180 category : micro
Original file line number Diff line number Diff line change 1+ require_relative '../harness/loader'
2+
3+ def array_each ( array )
4+ array . each do |x |
5+ x * 2
6+ end
7+ array . each do |x |
8+ x * 4
9+ end
10+ end
11+
12+ def array_map ( array )
13+ array . map do |x |
14+ x * 2
15+ end
16+ array . map do |x |
17+ x * 4
18+ end
19+ end
20+
21+ def array_select ( array )
22+ array . select do |x |
23+ x . even?
24+ end
25+ array . select do |x |
26+ x . odd?
27+ end
28+ end
29+
30+ def integer_times ( integer )
31+ integer . times do |i |
32+ i * 2
33+ end
34+ integer . times do |i |
35+ i * 4
36+ end
37+ end
38+
39+ def kernel_tap ( x )
40+ i = 0
41+ while i < x
42+ x . tap do |y |
43+ y * 2
44+ end
45+ x . tap do |y |
46+ y * 4
47+ end
48+ i += 1
49+ end
50+ end
51+
52+ def kernel_then ( x )
53+ i = 0
54+ while i < x
55+ x . then do |y |
56+ y * 2
57+ end
58+ x . then do |y |
59+ y * 4
60+ end
61+ i += 1
62+ end
63+ end
64+
65+ K = 100_000
66+ ARRAY = ( 1 ..K ) . to_a
67+
68+ run_benchmark ( 1000 ) do
69+ i = 0
70+ while i < 50
71+ array_each ( ARRAY )
72+ array_map ( ARRAY )
73+ array_select ( ARRAY )
74+ integer_times ( K )
75+ kernel_tap ( K )
76+ kernel_then ( K )
77+ i += 1
78+ end
79+ end
You can’t perform that action at this time.
0 commit comments