forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf_hooks: performance milestone time origin timestamp improvement
PR-URL: nodejs#51713 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
- Loading branch information
1 parent
782a7ed
commit a46247d
Showing
6 changed files
with
77 additions
and
27 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,45 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const common = require('../common.js'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e6], | ||
method: ['timeOrigin', 'toJSON'], | ||
}); | ||
|
||
function main({ method, n }) { | ||
switch (method) { | ||
case 'timeOrigin': | ||
benchTimeOrigin(n); | ||
break; | ||
case 'toJSON': | ||
benchToJSON(n); | ||
break; | ||
default: | ||
throw new Error(`Unsupported method ${method}`); | ||
} | ||
} | ||
|
||
function benchTimeOrigin(n) { | ||
const arr = []; | ||
for (let i = 0; i < n; ++i) { | ||
arr.push(performance.timeOrigin); | ||
} | ||
|
||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
arr[i] = performance.timeOrigin; | ||
} | ||
bench.end(n); | ||
|
||
assert.strictEqual(arr.length, n); | ||
} | ||
|
||
function benchToJSON(n) { | ||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
performance.toJSON(); | ||
} | ||
bench.end(n); | ||
} |
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
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