Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var test = require('fs').readFileSync('test-file.json', 'utf8');
  2. var ben = function(msg, fn) {
  3.    var time = process.hrtime();
  4.    for (var i=0; i<10000; i++) fn();
  5.    var diff = process.hrtime(time);
  6.    console.log(msg, (diff[0] * 1e9 + diff[1]) / 1e10, 'ms');
  7. }
  8.  
  9. var parser;
  10.  
  11. parser = JSON.parse;
  12. ben('JSON-native',   function(){return parser(test)});
  13.  
  14. parser = require('./JSON-js/json_parse');
  15. ben('JSON-js',       function(){return parser(test)});
  16.  
  17. parser = require('./JSON-js/json_parse_state');
  18. ben('JSON-js-state', function(){return parser(test)});
  19.  
  20. parser = require('js-yaml').safeLoad;
  21. ben('JS-YAML',       function(){return parser(test)});
  22.  
  23. parser = require('json5').parse;
  24. ben('JSON5',         function(){return parser(test)});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement