node/deps/v8/test/js-perf-test/SwitchStatements/switch_statement.js
Michaël Zasso 50930a0fa0
deps: update V8 to 9.3.345.16
PR-URL: https://github.com/nodejs/node/pull/39469
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2021-08-30 21:02:51 +02:00

30 lines
761 B
JavaScript

// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// running on old version takes approximately 50 seconds, so 50,000 milliseconds
new BenchmarkSuite('Big-Switch', [50000], [
new Benchmark('Big-Switch', false, false, 0, BigSwitch),
]);
function BigSwitch() {
"use strict";
const n = 100000;
const c = (a, b) => Array(a).fill().map((a, c) => b(c));
Function('n, c',
`
const a = c(n, a => a);
let ctr = 0;
for(let i = 0; i !== (1+n); i++){
switch(i){
${c(n, a => `case ${a}: ctr += i; break;`).join('\n')}
default: ctr += i; break;
}
}
return ctr;
`)(n,c);
}