index.js 740 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. const Benchmark = require('benchmark');
  3. const suite = new Benchmark.Suite;
  4. const testData = require('./test.json');
  5. const stringifyPackages = {
  6. // 'JSON.stringify': JSON.stringify,
  7. 'fast-json-stable-stringify': require('../index'),
  8. 'json-stable-stringify': true,
  9. 'fast-stable-stringify': true,
  10. 'faster-stable-stringify': true
  11. };
  12. for (const name in stringifyPackages) {
  13. let func = stringifyPackages[name];
  14. if (func === true) func = require(name);
  15. suite.add(name, function() {
  16. func(testData);
  17. });
  18. }
  19. suite
  20. .on('cycle', (event) => console.log(String(event.target)))
  21. .on('complete', function () {
  22. console.log('The fastest is ' + this.filter('fastest').map('name'));
  23. })
  24. .run({async: true});