Skip to content

Commit cdf1b8e

Browse files
committed
Fix core-string-equal benchmark to actually measure comparing bytes
* RopeNodes.BytesEqualNode was inline caching both LHS and RHS and so just returning a constant after checking if the Ropes were the same as before.
1 parent 52ceb57 commit cdf1b8e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

bench/micro/string/equal.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,27 @@ def str(n)
1313
Array.new(n, 'a'.ord).pack('C*')
1414
end
1515

16+
def are_equal?(a, b)
17+
a == b
18+
end
19+
1620
s1_small = str(small)
1721
s2_small = str(small)
1822

1923
s1_large = str(large)
2024
s2_large = str(large)
2125

22-
equal = s1_small == s2_small
23-
raise unless equal
24-
equal = s1_large == s2_large
25-
raise unless equal
26+
equal = false
27+
28+
[[s1_small, s2_small], [s1_large, s2_large]].each do |a, b|
29+
equal = are_equal?(a, b) # prevent splitting and identity caching
30+
raise unless equal
31+
end
2632

2733
benchmark "core-string-equal-#{small}" do
28-
equal = s1_small == s2_small
34+
equal = are_equal?(s1_small, s2_small)
2935
end
3036

3137
benchmark "core-string-equal-#{large}" do
32-
equal = s1_large == s2_large
38+
equal = are_equal?(s1_large, s2_large)
3339
end

0 commit comments

Comments
 (0)