Skip to content

Commit c2b1f66

Browse files
committed
bench: Avoid allocating an extra hash when not necessary
`JSON.parse(@JSON, symbolize_names: @Symbolize)` allocates an extra hash, which isn't necessary when `symbolize` is `false`. In the grand scheme of things, it's not a big deal, but on this sort of micro-benchmarks that can easily accound for a huge part of the runtime just because of the increased GC pressure.
1 parent 7388e5b commit c2b1f66

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

test/perf_strict.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ def capture_error(tag, orig, load_key, dump_key, &blk)
104104
puts 'Strict Parse Performance'
105105
perf = Perf.new()
106106
unless @failed.key?('JSON::Ext')
107-
perf.add('JSON::Ext', 'parse') { JSON.parse(@json, symbolize_names: @symbolize) }
107+
if @symbolize
108+
perf.add('JSON::Ext', 'parse') { JSON.parse(@json, symbolize_names: true) }
109+
else
110+
perf.add('JSON::Ext', 'parse') { JSON.parse(@json) }
111+
end
108112
perf.before('JSON::Ext') { JSON.parser = JSON::Ext::Parser }
109113
end
110114
unless @failed.key?('Oj:strict')

0 commit comments

Comments
 (0)