-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New timeout handling that uses a single active timer
We move to a new (yet again!) timeout handling system where we only use one active timer at a time, and track future timeouts / deadlines in our own queue to re-arm the timer. This fixes issue #52. We could use `setMaxListeners` to instead increase the timeout handlers allowed and keep with the existing design, but this approach is O(1) scalable.
- Loading branch information
Showing
7 changed files
with
194 additions
and
70 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*jshint node: true */ | ||
/*jslint unparam: true*/ | ||
'use strict'; | ||
|
||
/** | ||
* Check how fast various timers are in node. | ||
*/ | ||
|
||
var Benchmark = require('benchmark'); | ||
var Microtime = require('microtime'); | ||
|
||
var suite = new Benchmark.Suite(); | ||
|
||
// add tests | ||
suite.add('Date.now()', function() { | ||
// system time, not-monotonic, ms | ||
Date.now(); | ||
}) | ||
.add('Microtime.now()', function() { | ||
// system time, not-monotonic, us (POSIX: gettimeofday) | ||
Microtime.now(); | ||
}) | ||
.add('process.hrtime()', function() { | ||
// monotonic, ns (returns: [seconds, nanoseconds]) | ||
process.hrtime(); | ||
}) | ||
.add('process.hrtime() ms-round', function() { | ||
// monotonic, ns (returns: [seconds, nanoseconds]) | ||
var time = process.hrtime(); | ||
return (time[0] * 1000) + Math.round(time[1] / 1000000); | ||
}) | ||
.add('process.hrtime() ms-floor', function() { | ||
// monotonic, ns (returns: [seconds, nanoseconds]) | ||
var time = process.hrtime(); | ||
return (time[0] * 1000) + Math.floor(time[1] / 1000000); | ||
}) | ||
// add listeners | ||
.on('cycle', function(event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on('complete', function() { | ||
console.log('Fastest is ' + this.filter('fastest').map('name')); | ||
}) | ||
// run async | ||
.run({ 'async': true }); | ||
|
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
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
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
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
Oops, something went wrong.