Skip to content

Commit c30874c

Browse files
committed
WIP
1 parent 250b5a0 commit c30874c

File tree

2 files changed

+47
-25
lines changed

2 files changed

+47
-25
lines changed

benchmarks/binarytrees/benchmark.rb

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,47 @@
55
# Modified by Wesley Moxam
66
# *reset*
77

8-
def item_check(left, right)
9-
return 1 if left.nil?
10-
1 + item_check(*left) + item_check(*right)
11-
end
8+
module Btree
9+
extend self
1210

13-
def bottom_up_tree(depth)
14-
return [nil, nil] unless depth > 0
15-
depth -= 1
16-
[bottom_up_tree(depth), bottom_up_tree(depth)]
17-
end
11+
def item_check(left, right)
12+
return 1 if left.nil?
13+
1 + item_check(*left) + item_check(*right)
14+
end
1815

19-
max_depth = 14
20-
min_depth = 4
16+
def bottom_up_tree(depth)
17+
return [nil, nil] unless depth > 0
18+
depth -= 1
19+
[bottom_up_tree(depth), bottom_up_tree(depth)]
20+
end
2121

22-
max_depth = min_depth + 2 if min_depth + 2 > max_depth
23-
stretch_depth = max_depth + 1
22+
def bench
23+
max_depth = 14
24+
min_depth = 4
2425

25-
require_relative '../../harness/loader'
26+
max_depth = min_depth + 2 if min_depth + 2 > max_depth
27+
stretch_depth = max_depth + 1
2628

27-
run_benchmark(60) do
28-
stretch_tree = bottom_up_tree(stretch_depth)
29-
stretch_tree = nil
29+
stretch_tree = bottom_up_tree(stretch_depth)
30+
stretch_tree = nil
3031

31-
long_lived_tree = bottom_up_tree(max_depth)
32+
long_lived_tree = bottom_up_tree(max_depth)
3233

33-
min_depth.step(max_depth, 2) do |depth|
34-
iterations = 2**(max_depth - depth + min_depth)
34+
min_depth.step(max_depth, 2) do |depth|
35+
iterations = 2**(max_depth - depth + min_depth)
3536

36-
check = 0
37+
check = 0
3738

38-
for i in 1..iterations
39-
temp_tree = bottom_up_tree(depth)
40-
check += item_check(*temp_tree)
39+
for i in 1..iterations
40+
temp_tree = bottom_up_tree(depth)
41+
check += item_check(*temp_tree)
42+
end
4143
end
4244
end
4345
end
46+
47+
require_relative '../../harness/loader'
48+
49+
run_benchmark(60) do
50+
Btree.bench
51+
end

harness/harness.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ def realtime
3131
Process.clock_gettime(Process::CLOCK_MONOTONIC) - r0
3232
end
3333

34+
def run_once(&block)
35+
if parallel = ENV["RACTOR_PARALLEL"]
36+
# block = Ractor.make_shareable(block)
37+
realtime do
38+
ractors = Integer(parallel).times.map do
39+
Ractor.new(&block)
40+
end
41+
ractors.each(&:join)
42+
end
43+
else
44+
realtime(&block)
45+
end
46+
end
47+
3448
# Takes a block as input
3549
def run_benchmark(_num_itrs_hint, &block)
3650
times = []
@@ -50,7 +64,7 @@ def run_benchmark(_num_itrs_hint, &block)
5064
begin
5165
yjit_stats&.each_key { |key| yjit_stats[key] = RubyVM::YJIT.runtime_stats(key) }
5266

53-
time = realtime(&block)
67+
time = run_once(&block)
5468
num_itrs += 1
5569

5670
# NOTE: we may want to avoid this as it could trigger GC?

0 commit comments

Comments
 (0)