-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: refactor console benchmark
Fix and refactor the console benchmark. It did not test console so it got renamed and mainly tests the different ways of passing arguments through. PR-URL: #17707 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
1 parent
41e2bb1
commit 27227cf
Showing
3 changed files
with
62 additions
and
129 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,59 @@ | ||
'use strict'; | ||
|
||
const { createBenchmark } = require('../common.js'); | ||
const { format } = require('util'); | ||
|
||
const methods = [ | ||
'restAndSpread', | ||
'argumentsAndApply', | ||
'restAndApply', | ||
'predefined' | ||
]; | ||
|
||
const bench = createBenchmark(main, { | ||
method: methods, | ||
n: [1e6] | ||
}); | ||
|
||
function usingRestAndSpread(...args) { | ||
format(...args); | ||
} | ||
|
||
function usingRestAndApply(...args) { | ||
format.apply(null, args); | ||
} | ||
|
||
function usingArgumentsAndApply() { | ||
format.apply(null, arguments); | ||
} | ||
|
||
function usingPredefined() { | ||
format('part 1', 'part', 2, 'part 3', 'part', 4); | ||
} | ||
|
||
function main({ n, method, args }) { | ||
var fn; | ||
switch (method) { | ||
// '' is a default case for tests | ||
case '': | ||
case 'restAndSpread': | ||
fn = usingRestAndSpread; | ||
break; | ||
case 'restAndApply': | ||
fn = usingRestAndApply; | ||
break; | ||
case 'argumentsAndApply': | ||
fn = usingArgumentsAndApply; | ||
break; | ||
case 'predefined': | ||
fn = usingPredefined; | ||
break; | ||
default: | ||
throw new Error(`Unexpected method "${method}"`); | ||
} | ||
|
||
bench.start(); | ||
for (var i = 0; i < n; i++) | ||
fn('part 1', 'part', 2, 'part 3', 'part', 4); | ||
bench.end(n); | ||
} |
This file was deleted.
Oops, something went wrong.
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