Skip to content

Instantly share code, notes, and snippets.

@nickboyce
Created July 23, 2013 11:24
Show Gist options
  • Save nickboyce/6061660 to your computer and use it in GitHub Desktop.
Save nickboyce/6061660 to your computer and use it in GitHub Desktop.
require 'msgpack'
require 'json'
require 'benchmark'
o = {_id: 4086, created_at: "2002-12-01 00:00:00 UTC", updated_at: "2013-05-16 11:35:46 UTC", artist_id: "5165adb400e48fcc14000001", easyart_id: 4086, title: "The Tree of Life - Stoclet Frieze", tags: ["woman", "hug", "bedroom", "lounge"], available_media: ["paper", "canvas"], available_sizes: [], dominant_colour: [], original_medium: "Pencil / Ink / Pastel", artistic_movement: "Art Nouveau", shape: "landscape", supplier_id: "114", lead_time: 10, stock_level: 2, sales_per_day: 0.017771883289125, total_revenue: 285195, is_pod: false, category: [["figurative", "romance"], ["museum-art", "art-nouveau"]], category_slugs: [], edition_size: 0, price: 5499, original_price: nil, discount_percent: 0, status_id: nil, search_promotion: 0, copyright: nil, description: nil, height: nil, width: nil, easyart_ids: [], dominant_colours: ["gold"]}
a = []
100000.times do
a << o
end
Benchmark.bm do |x|
x.report("msgpack:") { puts "size=" + MessagePack.pack(a).length.to_s }
x.report("json:") { puts "size=" + a.to_json.length.to_s }
end
@nickboyce
Copy link
Author

user system total real
msgpack:size=67100005
1.660000 0.110000 1.770000 ( 1.797837)
json:size=83800001
6.580000 0.160000 6.740000 ( 6.762076)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment