[Intl] Add benchmark for toLocaleString/localeCompare

This is a bit of a performance bottleneck currently and
we're planning on improving performance by adding caching.
These benchmarks will allow us to measure the improvements
Add benchmark tests for
 String.prototype.localeCompare()
 Date.prototype.toLocaleString()
 Date.prototype.toLocaleDateString()
 Date.prototype.toLocaleTimeString()
 Number.prototype.toLocaleString()

Run with
python -u tools/run_perf.py --binary-override-path \
  out/x64.release/d8 --filter "JSTests/Strings/StringLocaleCompare" \
  test/js-perf-test/JSTests.json
python -u tools/run_perf.py --binary-override-path \
  out/x64.release/d8 --filter "JSTests/Dates" \
  test/js-perf-test/JSTests.json
python -u tools/run_perf.py --binary-override-path \
  out/x64.release/d8 --filter "JSTests/Numbers" \
  test/js-perf-test/JSTests.json

Before the landing of dffaff7769

 git reset --hard 474a6d6364
got
StringLocaleCompare-Strings(Score): 13240000
toLocaleDateString-Dates(Score): 1877000
toLocaleString-Dates(Score): 1197000
toLocaleTimeString-Dates(Score): 2147000
toLocaleDateString-Dates(Score): 1908000

After the landing of dffaff7769
 git reset --hard dffaff7769
got
StringLocaleCompare-Strings(Score): 97182
toLocaleDateString-Dates(Score): 10436
toLocaleString-Dates(Score): 10436
toLocaleTimeString-Dates(Score): 10669
toLocaleString-Numbers(Score): 2876


Bug: chromium:901748
Change-Id: Ibfea85fe668f1bfaacb2dfe08368cd920d2bbfc6
Reviewed-on: https://chromium-review.googlesource.com/c/1318099
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57323}
This commit is contained in:
Frank Tang 2018-11-06 12:22:43 -08:00 committed by Commit Bot
parent 1d0385cdd8
commit e23e1311b4
6 changed files with 103 additions and 2 deletions

View File

@ -0,0 +1,20 @@
// Copyright 2018 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('toLocaleString.js');
function PrintResult(name, result) {
console.log(name);
console.log(name + '-Dates(Score): ' + result);
}
function PrintError(name, error) {
PrintResult(name, error);
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });

View File

@ -0,0 +1,20 @@
// Copyright 2018 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.
function DateToLocaleDateString() {
let d = new Date();
d.toLocaleDateString()
}
createSuite('toLocaleDateString', 100000, DateToLocaleDateString, ()=>{});
function DateToLocaleString() {
let d = new Date();
d.toLocaleString()
}
createSuite('toLocaleString', 100000, DateToLocaleString, ()=>{});
function DateToLocaleTimeString() {
let d = new Date();
d.toLocaleTimeString()
}
createSuite('toLocaleTimeString', 100000, DateToLocaleTimeString, ()=>{});

View File

@ -482,6 +482,17 @@
{"name": "stringIndex_const"}
]
},
{
"name": "StringLocaleCompare",
"main": "run.js",
"resources": [ "string-localeCompare.js" ],
"test_flags": [ "string-localeCompare" ],
"results_regexp": "^%s\\-Strings\\(Score\\): (.+)$",
"run_count": 1,
"tests": [
{"name": "StringLocaleCompare"}
]
},
{
"name": "StringMatchAll",
"main": "run.js",
@ -1205,6 +1216,18 @@
}
]
},
{
"name": "Dates",
"path": ["Dates"],
"main": "run.js",
"resources": ["toLocaleString.js"],
"results_regexp": "^%s\\-Dates\\(Score\\): (.+)$",
"tests": [
{"name": "toLocaleDateString"},
{"name": "toLocaleString"},
{"name": "toLocaleTimeString"}
]
},
{
"name": "ExpressionDepth",
"path": ["ExpressionDepth"],
@ -1271,12 +1294,16 @@
"path": ["Numbers"],
"main": "run.js",
"flags": ["--allow-natives-syntax"],
"resources": [ "toNumber.js"],
"resources": [
"toNumber.js",
"toLocaleString.js"
],
"results_regexp": "^%s\\-Numbers\\(Score\\): (.+)$",
"tests": [
{"name": "Constructor"},
{"name": "UnaryPlus"},
{"name": "ParseFloat"}
{"name": "ParseFloat"},
{"name": "toLocaleString"}
]
},
{

View File

@ -3,6 +3,7 @@
// found in the LICENSE file.
load('../base.js');
load('toNumber.js');
load('toLocaleString.js');
function PrintResult(name, result) {
console.log(name);

View File

@ -0,0 +1,14 @@
// Copyright 2018 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.
function NumberToLocaleString() {
Number(0).toLocaleString()
Number(-12).toLocaleString()
Number(13).toLocaleString()
Number(123456789).toLocaleString()
Number(1234567.89).toLocaleString()
Number(-123456789).toLocaleString()
Number(-1234567.89).toLocaleString()
}
createSuite('toLocaleString', 100000, NumberToLocaleString, ()=>{});

View File

@ -0,0 +1,19 @@
// Copyright 2018 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('StringLocaleCompare', [1000000], [
new Benchmark('StringLocaleCompare', false, false, 0,
StringLocaleCompare),
]);
function StringLocaleCompare() {
var array = ["XYZ", "mno", "abc", "EFG", "ijk", "123", "tuv", "234", "efg"];
var sum = 0;
for (var j = 0; j < array.length; ++j) {
sum += "fox".localeCompare(array[j]);
}
return sum;
}