bench.js 556 B

1234567891011121314151617181920212223242526
  1. var fs = require('fs'),
  2. Parser = require('./jsonparse');
  3. var json = fs.readFileSync("samplejson/basic.json");
  4. while (true) {
  5. var start = Date.now();
  6. for (var i = 0; i < 1000; i++) {
  7. JSON.parse(json);
  8. }
  9. var first = Date.now() - start;
  10. start = Date.now();
  11. var p = new Parser();
  12. for (var i = 0; i < 1000; i++) {
  13. p.write(json);
  14. }
  15. var second = Date.now() - start;
  16. console.log("JSON.parse took %s", first);
  17. console.log("streaming parser took %s", second);
  18. console.log("streaming is %s times slower", second / first);
  19. }