From ac8b70cf2b91405f3be621460d300f371eb1c44f Mon Sep 17 00:00:00 2001 From: "dslomov@chromium.org" Date: Tue, 21 Oct 2014 11:05:32 +0000 Subject: [PATCH] Perf tests for harmony string functions. R=yangguo@chromium.org git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24765 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- test/js-perf-test/Strings/Strings.json | 12 ++++ test/js-perf-test/Strings/harmony-string.js | 66 +++++++++++++++++++++ test/js-perf-test/Strings/run.js | 27 +++++++++ 3 files changed, 105 insertions(+) create mode 100644 test/js-perf-test/Strings/Strings.json create mode 100644 test/js-perf-test/Strings/harmony-string.js create mode 100644 test/js-perf-test/Strings/run.js diff --git a/test/js-perf-test/Strings/Strings.json b/test/js-perf-test/Strings/Strings.json new file mode 100644 index 0000000000..61fdbd3664 --- /dev/null +++ b/test/js-perf-test/Strings/Strings.json @@ -0,0 +1,12 @@ +{ + "path": ["."], + "main": "run.js", + "flags": ["--harmony-strings"], + "run_count": 5, + "units": "score", + "results_regexp": "^%s\\-Strings\\(Score\\): (.+)$", + "total": true, + "tests": [ + {"name": "StringFunctions"} + ] +} diff --git a/test/js-perf-test/Strings/harmony-string.js b/test/js-perf-test/Strings/harmony-string.js new file mode 100644 index 0000000000..1d401068c1 --- /dev/null +++ b/test/js-perf-test/Strings/harmony-string.js @@ -0,0 +1,66 @@ +// Copyright 2014 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('StringFunctions', [1000], [ + new Benchmark('StringRepeat', false, false, 0, + StringRepeat, StringRepeatSetup, StringRepeatTearDown), + new Benchmark('StringStartsWith', false, false, 0, + StringStartsWith, StringWithSetup, StringWithTearDown), + new Benchmark('StringEndsWith', false, false, 0, + StringEndsWith, StringWithSetup, StringWithTearDown), + new Benchmark('StringContains', false, false, 0, + StringContains, StringContainsSetup, StringWithTearDown), +]); + + +var result; + +var stringRepeatSource = "abc"; + +function StringRepeatSetup() { + result = undefined; +} + +function StringRepeat() { + result = stringRepeatSource.repeat(500); +} + +function StringRepeatTearDown() { + var expected = ""; + for(var i = 0; i < 1000; i++) { + expected += stringRepeatSource; + } + return result === expected; +} + + +var str; +var substr; + +function StringWithSetup() { + str = "abc".repeat(500); + substr = "abc".repeat(200); + result = undefined; +} + +function StringWithTearDown() { + return !!result; +} + +function StringStartsWith() { + result = str.startsWith(substr); +} + +function StringEndsWith() { + result = str.endsWith(substr); +} + +function StringContainsSetup() { + str = "def".repeat(100) + "abc".repeat(100) + "qqq".repeat(100); + substr = "abc".repeat(100); +} + +function StringContains() { + result = str.contains(substr); +} diff --git a/test/js-perf-test/Strings/run.js b/test/js-perf-test/Strings/run.js new file mode 100644 index 0000000000..79ca26e68a --- /dev/null +++ b/test/js-perf-test/Strings/run.js @@ -0,0 +1,27 @@ +// Copyright 2014 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('harmony-string.js'); + + +var success = true; + +function PrintResult(name, result) { + print(name + '-Strings(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 });