-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: add more thorough timers benchmarks
Refs: #9493 PR-URL: #10925 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
- Loading branch information
1 parent
62f6749
commit 4d6fa8d
Showing
5 changed files
with
126 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
var common = require('../common.js'); | ||
var assert = require('assert'); | ||
|
||
var bench = common.createBenchmark(main, { | ||
thousands: [500], | ||
}); | ||
|
||
function main(conf) { | ||
var iterations = +conf.thousands * 1e3; | ||
|
||
var timer = setTimeout(() => {}, 1); | ||
for (var i = 0; i < iterations; i++) { | ||
setTimeout(cb, 1); | ||
} | ||
var next = timer._idlePrev; | ||
clearTimeout(timer); | ||
|
||
bench.start(); | ||
|
||
for (var j = 0; j < iterations; j++) { | ||
timer = next; | ||
next = timer._idlePrev; | ||
clearTimeout(timer); | ||
} | ||
|
||
bench.end(iterations / 1e3); | ||
} | ||
|
||
function cb() { | ||
assert(false, 'Timer should not call callback'); | ||
} |
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,26 @@ | ||
'use strict'; | ||
var common = require('../common.js'); | ||
var assert = require('assert'); | ||
|
||
var bench = common.createBenchmark(main, { | ||
thousands: [100], | ||
}); | ||
|
||
function main(conf) { | ||
var iterations = +conf.thousands * 1e3; | ||
|
||
var timersList = []; | ||
for (var i = 0; i < iterations; i++) { | ||
timersList.push(setTimeout(cb, i + 1)); | ||
} | ||
|
||
bench.start(); | ||
for (var j = 0; j < iterations + 1; j++) { | ||
clearTimeout(timersList[j]); | ||
} | ||
bench.end(iterations / 1e3); | ||
} | ||
|
||
function cb() { | ||
assert(false, 'Timer ' + this._idleTimeout + ' should not call callback'); | ||
} |
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,18 @@ | ||
'use strict'; | ||
var common = require('../common.js'); | ||
|
||
var bench = common.createBenchmark(main, { | ||
thousands: [500], | ||
}); | ||
|
||
function main(conf) { | ||
var iterations = +conf.thousands * 1e3; | ||
|
||
bench.start(); | ||
|
||
for (var i = 0; i < iterations; i++) { | ||
setTimeout(() => {}, 1); | ||
} | ||
|
||
bench.end(iterations / 1e3); | ||
} |
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,27 @@ | ||
'use strict'; | ||
var common = require('../common.js'); | ||
var assert = require('assert'); | ||
|
||
var bench = common.createBenchmark(main, { | ||
thousands: [100], | ||
}); | ||
|
||
function main(conf) { | ||
var iterations = +conf.thousands * 1e3; | ||
|
||
var timersList = []; | ||
|
||
bench.start(); | ||
for (var i = 0; i < iterations; i++) { | ||
timersList.push(setTimeout(cb, i + 1)); | ||
} | ||
bench.end(iterations / 1e3); | ||
|
||
for (var j = 0; j < iterations + 1; j++) { | ||
clearTimeout(timersList[j]); | ||
} | ||
} | ||
|
||
function cb() { | ||
assert(false, 'Timer ' + this._idleTimeout + ' should not call callback'); | ||
} |
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,23 @@ | ||
'use strict'; | ||
var common = require('../common.js'); | ||
|
||
var bench = common.createBenchmark(main, { | ||
thousands: [500], | ||
}); | ||
|
||
function main(conf) { | ||
var iterations = +conf.thousands * 1e3; | ||
var count = 0; | ||
|
||
for (var i = 0; i < iterations; i++) { | ||
setTimeout(cb, 1); | ||
} | ||
|
||
bench.start(); | ||
|
||
function cb() { | ||
count++; | ||
if (count === iterations) | ||
bench.end(iterations / 1e3); | ||
} | ||
} |