Skip to content

Commit c164135

Browse files
committed
📉 Fix benchmark data for SequenceSet#normalize
I'd forgotten that `SequenceSet#append` partially normalizes its input (no sorting nor coalescing, but each entry is converted to normal form). But the benchmark was specifically meant to test the non-normal forms.
1 parent 6747838 commit c164135

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

benchmarks/sequence_set-normalize.yml

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ prelude: |
66
INPUT_COUNT = Integer ENV.fetch("BENCHMARK_INPUT_COUNT", 1000)
77
MAX_INPUT = Integer ENV.fetch("BENCHMARK_MAX_INPUT", 1400)
88
WARMUP_RUNS = Integer ENV.fetch("BENCHMARK_WARMUP_RUNS", 200)
9+
SHUFFLE_PCT = Float ENV.fetch("BENCHMARK_SHUFFLE_PCT", 0.2)
10+
ABNORMAL_PCT = Float ENV.fetch("BENCHMARK_ABNORMAL_PCT", 0.2)
911
1012
def init_sets(count: 100, set_size: INPUT_COUNT, max: MAX_INPUT)
1113
Array.new(count) {
@@ -22,31 +24,48 @@ prelude: |
2224
.map(&:freeze)
2325
end
2426
27+
def shuffle_entries(seqset)
28+
case SHUFFLE_PCT
29+
in 1.0... then seqset.entries.shuffle
30+
in ...0.0 then raise RangeError, "SHUFFLE_PCT should be positive"
31+
else
32+
unsorted, entries = seqset.entries.partition { rand < SHUFFLE_PCT }
33+
unsorted.each do |entry|
34+
entries.insert(rand(0..entries.size), entry)
35+
end
36+
entries
37+
end
38+
end
39+
2540
def init_unsorted_sets(...)
2641
init_sets(...)
2742
.each do |seqset|
28-
entries = seqset.entries.shuffle
43+
entries = shuffle_entries(seqset)
2944
seqset.clear
3045
entries.each do |entry|
3146
seqset.append entry
3247
end
3348
end
3449
end
3550
51+
def abnormal_form(seqset)
52+
seqset.entries
53+
.map {|entry|
54+
if ABNORMAL_PCT < rand
55+
entry.is_a?(Range) ? "#{entry.begin}:#{entry.end || :*}" : entry
56+
elsif entry.is_a? Range
57+
"#{entry.end || "*"}:#{entry.begin}"
58+
else
59+
"#{entry}:#{entry}"
60+
end
61+
}
62+
.join(",")
63+
end
64+
3665
def init_abnormal_sets(...)
3766
init_sets(...)
3867
.each do |seqset|
39-
entries = seqset.entries.shuffle
40-
seqset.clear
41-
entries.each do |entry|
42-
if [true, false].sample
43-
seqset.append entry
44-
elsif entry.is_a? Range
45-
seqset.append "#{entry.end || "*"}:#{entry.begin}"
46-
else
47-
seqset.append "#{entry}:#{entry}"
48-
end
49-
end
68+
seqset.string = abnormal_form(seqset)
5069
end
5170
end
5271

0 commit comments

Comments
 (0)