Skip to content

Instantly share code, notes, and snippets.

@geek
Last active September 24, 2015 02:50
Show Gist options
  • Save geek/66544c72301e83912cf6 to your computer and use it in GitHub Desktop.
Save geek/66544c72301e83912cf6 to your computer and use it in GitHub Desktop.
JSON.parse vs jsonic

Code

var jsonic = require('jsonic')
var input = '{ "foo": "bar", "red": 1 }'

exports.compare = {
  'jsonic': function () {
    jsonic(input)
  },
  'json': function () {
    JSON.parse(input)
  }
}
require('bench').runMain()

Output

{ http_parser: '2.5.0',
  node: '4.1.0',
  v8: '4.5.103.33',
  uv: '1.7.4',
  zlib: '1.2.8',
  ares: '1.10.1-DEV',
  modules: '46',
  openssl: '1.0.2d' }
(node) util.print is deprecated. Use console.log instead.
Scores: (bigger is better)

json
Raw:
 > 1728.2717282717283
 > 1975.024975024975
 > 1980.01998001998
 > 1946.053946053946
Average (mean) 1907.3426573426573

jsonic
Raw:
 > 33.59683794466403
 > 33.79721669980119
 > 33.49753694581281
 > 30.392156862745097
Average (mean) 32.82093711325578

Winner: json
Compared with next highest (jsonic), it's:
98.28% faster
58.11 times as fast
1.76 order(s) of magnitude faster
A LOT FASTER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment