Skip to content

Instantly share code, notes, and snippets.

@frsyuki
Created April 15, 2019 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frsyuki/9777c4adba2b5c957695b64f17b64ba1 to your computer and use it in GitHub Desktop.
Save frsyuki/9777c4adba2b5c957695b64f17b64ba1 to your computer and use it in GitHub Desktop.
require 'benchmark'
require 'json'
require 'yajl'
require 'msgpack'
here = File.dirname(File.expand_path(__FILE__))
# https://catalog.data.gov/dataset/consumer-complaint-database
VIEWS_OBJ = JSON.load(File.read("#{here}/views.json"))
VIEWS_MSGPACK = MessagePack.pack(VIEWS_OBJ)
VIEWS_JSON = JSON.dump(VIEWS_OBJ)
# https://www.justice.gov/api/v1/blog_entries.json
BLOG_OBJ = JSON.load(File.read("#{here}/blog_entries.json"))
BLOG_MSGPACK = MessagePack.pack(BLOG_OBJ)
BLOG_JSON = JSON.dump(BLOG_OBJ)
# r = Random.new(3); File.write("profiler/integers.json", 100000.times.map {|i| r.rand(i+1) }.to_json)
INTEGERS_OBJ = JSON.load(File.read("#{here}/integers.json"))
INTEGERS_MSGPACK = MessagePack.pack(INTEGERS_OBJ)
INTEGERS_JSON = JSON.dump(INTEGERS_OBJ)
UNPACK_PARAMS = {write_reference_threshold: 256, symbolize_keys: true}
PACK_PARAMS = {write_reference_threshold: 256}
Benchmark.bmbm(10) do |x|
x.report("views-ser") do
for a in 1..30000 do
JSON.dump(VIEWS_OBJ)
end
end
x.report("views-deser") do
for a in 1..7000 do
JSON.load(VIEWS_JSON)
end
end
x.report("blog-ser") do
for a in 1..150000 do
JSON.dump(BLOG_OBJ)
end
end
x.report("blog-deser") do
for a in 1..50000 do
JSON.load(BLOG_JSON)
end
end
x.report("integers-ser") do
for a in 1..6000 do
JSON.dump(INTEGERS_OBJ)
end
end
x.report("integers-deser") do
for a in 1..3000 do
JSON.load(INTEGERS_JSON)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment