Commit e2670e80 authored by Caitlin Potter's avatar Caitlin Potter Committed by Commit Bot

[js-perf-test] add microbenchmarks for C-style for loops

Adds some benchmarks copied from v8:4762.

BUG=v8:4762, v8:5460
R=adamk@chromium.org

Change-Id: I0b96080042781c2c46c0c8a3896a921bde97c1e5
Reviewed-on: https://chromium-review.googlesource.com/475934Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Cr-Commit-Position: refs/heads/master@{#44629}
parent a738ad33
// 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.
new BenchmarkSuite('Let-Standard', [1000], [
new Benchmark('Let-Standard', false, false, 0, LetLoop),
]);
new BenchmarkSuite('Var-Standard', [1000], [
new Benchmark('Var-Standard', false, false, 0, VarLoop),
]);
var x = [-1, 1, 4];
var y = [-11, -1, 1, 2, 3, 4, 5, 6, 20, 44, 87, 99, 100];
function LetLoop() {
"use strict";
const ret = [];
for (let i = 0; i < x.length; i++) {
for (let z = 0; z < y.length; z++) {
if (x[i] == y[z]) {
ret.push(x[i]);
break;
}
}
}
return ret;
}
function VarLoop() {
"use strict";
const ret = [];
for (var i = 0; i < x.length; i++) {
for (var z = 0; z < y.length; z++) {
if (x[i] == y[z]) {
ret.push(x[i]);
break;
}
}
}
return ret;
}
// 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.
load('../base.js');
load('for_loop.js');
var success = true;
function PrintResult(name, result) {
print(name + '-ForLoop(Score): ' + result);
}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });
......@@ -382,6 +382,19 @@
{"name": "FastMap"},
{"name": "ObjectMap"}
]
},
{
"name": "ForLoops",
"path": ["ForLoops"],
"main": "run.js",
"resources": [
"for_loop.js"
],
"results_regexp": "^%s\\-ForLoop\\(Score\\): (.+)$",
"tests": [
{"name": "Let-Standard"},
{"name": "Var-Standard"}
]
}
]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment