Skip to content

Instantly share code, notes, and snippets.

@janzikan
Created June 19, 2018 07:51
Show Gist options
  • Save janzikan/8506cb21c8e508bc423bb30e52eb992d to your computer and use it in GitHub Desktop.
Save janzikan/8506cb21c8e508bc423bb30e52eb992d to your computer and use it in GitHub Desktop.
Ruby: yajl vs oj benchmark
require 'benchmark/ips'
require 'oj'
require 'yajl'
FILENAME = 'tweet.json'.freeze
json = File.read(FILENAME)
Benchmark.ips do |x|
x.config(time: 20, warmup: 2)
x.report('yajl parser') do
Yajl::Parser.parse(json)
end
x.report('oj parser') do
Oj.load(json)
end
x.compare!
end
Results when relatively large JSON file (3 075B) is parsed
Warming up --------------------------------------
yajl parser 1.487k i/100ms
oj parser 2.353k i/100ms
Calculating -------------------------------------
yajl parser 13.258k (±14.9%) i/s - 258.738k in 20.044143s
oj parser 22.691k (±15.0%) i/s - 440.011k in 20.031725s
Comparison:
oj parser: 22691.2 i/s
yajl parser: 13258.1 i/s - 1.71x slower
---
Results when small JSON file (53B) is parsed
Warming up --------------------------------------
yajl parser 30.044k i/100ms
oj parser 51.803k i/100ms
Calculating -------------------------------------
yajl parser 348.436k (± 3.2%) i/s - 6.970M in 20.025251s
oj parser 619.713k (± 3.4%) i/s - 12.381M in 20.005138s
Comparison:
oj parser: 619713.3 i/s
yajl parser: 348436.4 i/s - 1.78x slower
{
"account_id": "acc123",
"user_id": "user123"
}
{
"data": {
"created_at": "Fri Jun 06 17:49:39 +0000 2014",
"id": 474971393852182500,
"id_str": "474971393852182528",
"text": "We can neither confirm nor deny that this is our first tweet.",
"truncated": false,
"entities": {
"hashtags": [],
"symbols": [],
"user_mentions": [],
"urls": []
},
"source": "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>",
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 2359926157,
"id_str": "2359926157",
"name": "CIA",
"screen_name": "CIA",
"location": "Langley, VA",
"description": "We are the Nation's first line of defense. We accomplish what others cannot accomplish and go where others cannot go.",
"url": "http://t.co/3PkAkcbfw9",
"entities": {
"url": {
"urls": [
{
"url": "http://t.co/3PkAkcbfw9",
"expanded_url": "http://cia.gov",
"display_url": "cia.gov",
"indices": [
0,
22
]
}
]
},
"description": {
"urls": []
}
},
"protected": false,
"followers_count": 2348135,
"friends_count": 31,
"listed_count": 9073,
"created_at": "Mon Feb 24 19:08:11 +0000 2014",
"favourites_count": 105,
"utc_offset": null,
"time_zone": null,
"geo_enabled": false,
"verified": true,
"statuses_count": 3774,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "000000",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme14/bg.gif",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme14/bg.gif",
"profile_background_tile": false,
"profile_image_url": "http://pbs.twimg.com/profile_images/474250448757481472/QcQ_P01E_normal.jpeg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/474250448757481472/QcQ_P01E_normal.jpeg",
"profile_banner_url": "https://pbs.twimg.com/profile_banners/2359926157/1401488215",
"profile_link_color": "1B95E0",
"profile_sidebar_border_color": "000000",
"profile_sidebar_fill_color": "000000",
"profile_text_color": "000000",
"profile_use_background_image": false,
"has_extended_profile": true,
"default_profile": false,
"default_profile_image": false,
"following": false,
"follow_request_sent": false,
"notifications": false,
"translator_type": "none"
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 310771,
"favorite_count": 246692,
"favorited": false,
"retweeted": false,
"lang": "en"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment