date_YYYYMMDD.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*!
  2. * utility - benchmark/date_YYYYMMDD.js
  3. * Copyright(c) 2013 fengmk2 <fengmk2@gmail.com>
  4. * MIT Licensed
  5. */
  6. "use strict";
  7. /**
  8. * Module dependencies.
  9. */
  10. // http://jsperf.com/access-log-date-format
  11. var utils = require('../');
  12. var moment = require('moment');
  13. var Benchmark = require('benchmark');
  14. var suite = new Benchmark.Suite();
  15. console.log('parseInt(moment().format("YYYYMMDD"), 10): %j', parseInt(moment().format('YYYYMMDD'), 10));
  16. console.log('utils.datestruct().YYYYMMDD: %j', utils.datestruct().YYYYMMDD);
  17. console.log('new Date().toString(): %j', new Date().toString());
  18. console.log('------------------------');
  19. suite
  20. .add("parseInt(moment().format('YYYYMMDD'), 10)", function () {
  21. parseInt(moment().format('YYYYMMDD'), 10);
  22. })
  23. .add('utils.datestruct().YYYYMMDD', function () {
  24. utils.datestruct().YYYYMMDD;
  25. })
  26. .add('new Date().toString()', function () {
  27. new Date().toString();
  28. })
  29. // add listeners
  30. .on('cycle', function (event) {
  31. console.log(String(event.target));
  32. })
  33. .on('complete', function () {
  34. console.log('Fastest is ' + this.filter('fastest').pluck('name'));
  35. })
  36. .run({ async: false });