Skip to content

Commit fb68e72

Browse files
committed
style
1 parent d4fc055 commit fb68e72

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

Gemfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ gem "ruby_memcheck", "~> 2.3" if RUBY_VERSION >= "2.7"
2121

2222
# benchmarks
2323
if RUBY_VERSION >= "2.7"
24-
gem "json", "~> 2.13"
25-
gem "oj", "~> 3.16"
2624
gem "benchmark", "~> 0.4.1"
2725
gem "benchmark-ips", "~> 2.14"
2826
gem "benchmark-memory", "~> 0.2.0"
27+
gem "json", "~> 2.13"
28+
gem "oj", "~> 3.16"
2929
# for ':stats => :bootstrap'
3030
# gem "kalibera", "~> 0.1.2"
31-
gem "rb_json5", "~> 0.3.0"
32-
gem "json-next", "~> 1.2"
3331
gem "activesupport", "~> 7.1"
32+
gem "json-next", "~> 1.2"
3433
gem "rainbow", "~> 3.1"
34+
gem "rb_json5", "~> 0.3.0"
3535
end

Rakefile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ if RUBY_VERSION >= "2.7"
3535
RubyMemcheck::RSpec::RakeTask.new(valgrind: :compile)
3636
end
3737

38+
# rubocop:disable Metrics/BlockLength
3839
task bench: :compile do
3940
require "benchmark"
4041
require "benchmark/ips"
@@ -48,25 +49,26 @@ if RUBY_VERSION >= "2.7"
4849
require "json_scanner"
4950

5051
json_str = File.read("spec/graphql_response.json")
51-
json_path = [:data, :search, :searchResult, :paginationV2, :maxPage]
52+
json_path = %i[data search searchResult paginationV2 maxPage]
5253
json_selector = JsonScanner::Config.new([json_path])
5354

5455
# TODO: better title display
5556
puts "\n\n\n"
56-
title = "========= JSON string size: #{ActiveSupport::NumberHelper.number_to_human_size(json_str.bytesize)} ========="
57+
json_str_size = ActiveSupport::NumberHelper.number_to_human_size(json_str.bytesize)
58+
title = "========= JSON string size: #{json_str_size} ========="
5759
puts Rainbow(title).color(136, 17, 2)
58-
page_size_with_json = -> do
60+
page_size_with_json = lambda do
5961
JSON.parse(json_str, symbolize_names: true).dig(*json_path)
6062
end
61-
page_size_with_oj = -> do
63+
page_size_with_oj = lambda do
6264
Oj.load(json_str, symbolize_names: true, mode: :object).dig(*json_path)
6365
end
64-
page_size_with_json_scanner_scan = -> do
66+
page_size_with_json_scanner_scan = lambda do
6567
JsonScanner.scan(json_str, json_selector).first.first.then do |begin_pos, end_pos, _type|
6668
JSON.parse(json_str.byteslice(begin_pos...end_pos), quirks_mode: true)
6769
end
6870
end
69-
page_size_with_json_scanner_parse = -> do
71+
page_size_with_json_scanner_parse = lambda do
7072
JsonScanner.parse(json_str, json_selector, symbolize_path_keys: true).dig(*json_path)
7173
end
7274

@@ -76,9 +78,10 @@ if RUBY_VERSION >= "2.7"
7678
page_size_with_json_scanner_scan.call,
7779
page_size_with_json_scanner_parse.call,
7880
]
79-
puts Rainbow("path #{json_path.map(&:inspect).join(", ")}; extracted values: #{results}").send(results.uniq.size == 1 ? :green : :red)
81+
results_report = "path #{json_path.map(&:inspect).join(", ")}; extracted values: #{results}"
82+
puts Rainbow(results_report).send(results.uniq.size == 1 ? :green : :red)
8083

81-
benchmark = ->(type, x) do
84+
benchmark = lambda do |type, x|
8285
# not supported by 'memory'
8386
# x.config(:stats => :bootstrap, :confidence => 95)
8487

@@ -94,6 +97,7 @@ if RUBY_VERSION >= "2.7"
9497
puts Rainbow("=" * title.size).color(136, 17, 2)
9598
puts "\n\n\n"
9699
end
100+
# rubocop:enable Metrics/BlockLength
97101
end
98102

99103
# ========= JSON string size: 463 KB =========
@@ -137,8 +141,6 @@ end
137141
# json: 1987269 allocated - 5400.19x more
138142
# ============================================
139143

140-
141-
142144
# ========= JSON string size: 463 KB =========
143145
# path :data, :search, :searchResult, :paginationV2, :maxPage; extracted values: [8, 8, 8, 8]
144146
# ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
@@ -180,8 +182,6 @@ end
180182
# oj: 1440774 allocated - 3915.15x more
181183
# ============================================
182184

183-
184-
185185
# ========= JSON string size: 463 KB =========
186186
# path :data, :search, :searchResult, :paginationV2, :maxPage; extracted values: [8, 8, 8, 8]
187187
# ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [x86_64-linux]

0 commit comments

Comments
 (0)