Created
December 20, 2012 14:32
-
-
Save fengmk2/4345606 to your computer and use it in GitHub Desktop.
Date.now VS microtime.now()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Benchmark = require('benchmark'); | |
var microtime = require('microtime'); | |
var suite = new Benchmark.Suite(); | |
suite | |
.add('Date.now()', function () { | |
var diff1 = Date.now() - Date.now(); | |
}) | |
.add('microtime.now()', function () { | |
var diff2 = microtime.now() - microtime.now(); | |
}) | |
.add('process.uptime()', function () { | |
var diff3 = process.uptime() - process.uptime(); | |
}) | |
.add('process.hrtime()', function () { | |
var t = process.hrtime(); | |
var diff4 = process.hrtime(t); | |
}) | |
// add listeners | |
.on('cycle', function (event, bench) { | |
console.log(String(bench)); | |
}) | |
.on('complete', function () { | |
console.log('Fastest is ' + this.filter('fastest').pluck('name')); | |
}) | |
.run(); |
danthegoodman
commented
Sep 20, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment