From e71e21c18131795c1b24f65d21b3be422cdbe1f1 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Tue, 28 Dec 2021 02:32:12 +0200 Subject: [PATCH] Add WTF-8 related perf tests --- tests/perf/test-string-endswith-ascii-1.js | 35 +++++++++++++ tests/perf/test-string-endswith-nonascii-1.js | 35 +++++++++++++ tests/perf/test-string-indexof-1.js | 29 +++++++++++ tests/perf/test-string-lastindexof-1.js | 29 +++++++++++ ...test-string-random-access-nonascii-long.js | 42 ++++++++++++++++ .../test-string-random-access-nonascii.js | 42 ++++++++++++++++ tests/perf/test-string-replace-ascii-1.js | 29 +++++++++++ tests/perf/test-string-replace-ascii-2.js | 29 +++++++++++ tests/perf/test-string-replace-nonbmp-1.js | 29 +++++++++++ tests/perf/test-string-replace-nonbmp-2.js | 29 +++++++++++ tests/perf/test-string-scan-nonascii-long.js | 50 +++++++++++++++++++ tests/perf/test-string-scan-nonascii.js | 22 ++++---- tests/perf/test-string-split-nonbmp-1.js | 29 +++++++++++ tests/perf/test-string-startswith-ascii-1.js | 35 +++++++++++++ .../perf/test-string-startswith-nonascii-1.js | 35 +++++++++++++ tests/perf/test-string-substring-ascii-1.js | 33 ++++++++++++ tests/perf/test-string-substring-ascii-2.js | 33 ++++++++++++ tests/perf/test-string-substring-ascii-3.js | 33 ++++++++++++ .../perf/test-string-substring-nonascii-1.js | 33 ++++++++++++ .../perf/test-string-substring-nonascii-2.js | 33 ++++++++++++ .../perf/test-string-substring-nonascii-3.js | 33 ++++++++++++ 21 files changed, 686 insertions(+), 11 deletions(-) create mode 100644 tests/perf/test-string-endswith-ascii-1.js create mode 100644 tests/perf/test-string-endswith-nonascii-1.js create mode 100644 tests/perf/test-string-indexof-1.js create mode 100644 tests/perf/test-string-lastindexof-1.js create mode 100644 tests/perf/test-string-random-access-nonascii-long.js create mode 100644 tests/perf/test-string-random-access-nonascii.js create mode 100644 tests/perf/test-string-replace-ascii-1.js create mode 100644 tests/perf/test-string-replace-ascii-2.js create mode 100644 tests/perf/test-string-replace-nonbmp-1.js create mode 100644 tests/perf/test-string-replace-nonbmp-2.js create mode 100644 tests/perf/test-string-scan-nonascii-long.js create mode 100644 tests/perf/test-string-split-nonbmp-1.js create mode 100644 tests/perf/test-string-startswith-ascii-1.js create mode 100644 tests/perf/test-string-startswith-nonascii-1.js create mode 100644 tests/perf/test-string-substring-ascii-1.js create mode 100644 tests/perf/test-string-substring-ascii-2.js create mode 100644 tests/perf/test-string-substring-ascii-3.js create mode 100644 tests/perf/test-string-substring-nonascii-1.js create mode 100644 tests/perf/test-string-substring-nonascii-2.js create mode 100644 tests/perf/test-string-substring-nonascii-3.js diff --git a/tests/perf/test-string-endswith-ascii-1.js b/tests/perf/test-string-endswith-ascii-1.js new file mode 100644 index 00000000..90bc0a12 --- /dev/null +++ b/tests/perf/test-string-endswith-ascii-1.js @@ -0,0 +1,35 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var str = []; + var i; + + for (i = 0; i < 1024; i++) { + str.push(i & 0x7f); + } + str = String.fromCharCode.apply(null, str); + print(str.length); + + var suffix1 = str.substr(str.length - 10, str.length); + var suffix2 = '_' + suffix1; // No match. + + for (i = 0; i < 1e6; i++) { + void str.endsWith(suffix1); + void str.endsWith(suffix2); + void str.endsWith(suffix1); + void str.endsWith(suffix2); + void str.endsWith(suffix1); + void str.endsWith(suffix2); + void str.endsWith(suffix1); + void str.endsWith(suffix2); + void str.endsWith(suffix1); + void str.endsWith(suffix2); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-endswith-nonascii-1.js b/tests/perf/test-string-endswith-nonascii-1.js new file mode 100644 index 00000000..f7fded80 --- /dev/null +++ b/tests/perf/test-string-endswith-nonascii-1.js @@ -0,0 +1,35 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var str = []; + var i; + + for (i = 0; i < 1024; i++) { + str.push(i & 0xffff); + } + str = String.fromCharCode.apply(null, str); + print(str.length); + + var suffix1 = str.substr(str.length - 10, str.length); + var suffix2 = '_' + suffix1; // No match. + + for (i = 0; i < 1e6; i++) { + void str.endsWith(suffix1); + void str.endsWith(suffix2); + void str.endsWith(suffix1); + void str.endsWith(suffix2); + void str.endsWith(suffix1); + void str.endsWith(suffix2); + void str.endsWith(suffix1); + void str.endsWith(suffix2); + void str.endsWith(suffix1); + void str.endsWith(suffix2); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-indexof-1.js b/tests/perf/test-string-indexof-1.js new file mode 100644 index 00000000..be09e9c7 --- /dev/null +++ b/tests/perf/test-string-indexof-1.js @@ -0,0 +1,29 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var i; + var x; + + x = 'foobar\u{1f4a9}'.repeat(1000); + console.log(x); + + for (i = 0; i < 1e5; i++) { + void x.indexOf('\u{1f4a9}'); + void x.indexOf('\u{1f4a9}', 3000); + void x.indexOf('\u{1f4a9}'); + void x.indexOf('\u{1f4a9}', 3000); + void x.indexOf('\u{1f4a9}'); + void x.indexOf('\u{1f4a9}', 3000); + void x.indexOf('\u{1f4a9}'); + void x.indexOf('\u{1f4a9}', 3000); + void x.indexOf('\u{1f4a9}'); + void x.indexOf('\u{1f4a9}', 3000); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-lastindexof-1.js b/tests/perf/test-string-lastindexof-1.js new file mode 100644 index 00000000..142ee2cf --- /dev/null +++ b/tests/perf/test-string-lastindexof-1.js @@ -0,0 +1,29 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var i; + var x; + + x = 'foobar\u{1f4a9}'.repeat(1000); + console.log(x); + + for (i = 0; i < 1e5; i++) { + void x.lastIndexOf('\u{1f4a9}'); + void x.lastIndexOf('\u{1f4a9}', 3000); + void x.lastIndexOf('\u{1f4a9}'); + void x.lastIndexOf('\u{1f4a9}', 3000); + void x.lastIndexOf('\u{1f4a9}'); + void x.lastIndexOf('\u{1f4a9}', 3000); + void x.lastIndexOf('\u{1f4a9}'); + void x.lastIndexOf('\u{1f4a9}', 3000); + void x.lastIndexOf('\u{1f4a9}'); + void x.lastIndexOf('\u{1f4a9}', 3000); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-random-access-nonascii-long.js b/tests/perf/test-string-random-access-nonascii-long.js new file mode 100644 index 00000000..b73469dc --- /dev/null +++ b/tests/perf/test-string-random-access-nonascii-long.js @@ -0,0 +1,42 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var str = []; + var i; + + for (i = 0; i < 65536; i++) { + str.push(i & 0xffff); + } + str = String.fromCharCode.apply(null, str).repeat(64); + print(str.length); + + /* Because this testcase is not about interning, intern the substrings + * to avoid string table traffic in this particular test. + */ + var dummy = []; + while (dummy.length < 0x10000) { + dummy.push(String.fromCharCode(dummy.length)); + } + print(dummy.length); + + var strlen = str.length; + for (i = 0; i < 250; i++) { + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-random-access-nonascii.js b/tests/perf/test-string-random-access-nonascii.js new file mode 100644 index 00000000..64259f7a --- /dev/null +++ b/tests/perf/test-string-random-access-nonascii.js @@ -0,0 +1,42 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var str = []; + var i; + + for (i = 0; i < 1024; i++) { + str.push(i & 0xffff); + } + str = String.fromCharCode.apply(null, str); + print(str.length); + + /* Because this testcase is not about interning, intern the substrings + * to avoid string table traffic in this particular test. + */ + var dummy = []; + while (dummy.length < 0x10000) { + dummy.push(String.fromCharCode(dummy.length)); + } + print(dummy.length); + + var strlen = str.length; + for (i = 0; i < 1e6; i++) { + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + void str.charCodeAt(Math.random() * strlen); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-replace-ascii-1.js b/tests/perf/test-string-replace-ascii-1.js new file mode 100644 index 00000000..6e5fb609 --- /dev/null +++ b/tests/perf/test-string-replace-ascii-1.js @@ -0,0 +1,29 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var i; + var x; + + x = 'foobarX'.repeat(1000); + console.log(x); + + for (i = 0; i < 1e5; i++) { + void x.replace('X', 'ZZ'); + void x.replace('X', 'ZZ'); + void x.replace('X', 'ZZ'); + void x.replace('X', 'ZZ'); + void x.replace('X', 'ZZ'); + void x.replace('X', 'ZZ'); + void x.replace('X', 'ZZ'); + void x.replace('X', 'ZZ'); + void x.replace('X', 'ZZ'); + void x.replace('X', 'ZZ'); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-replace-ascii-2.js b/tests/perf/test-string-replace-ascii-2.js new file mode 100644 index 00000000..e86be9b9 --- /dev/null +++ b/tests/perf/test-string-replace-ascii-2.js @@ -0,0 +1,29 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var i; + var x; + + x = 'foobarX'.repeat(1000); + console.log(x); + + for (i = 0; i < 5e2; i++) { + void x.replace(/X/g, 'ZZ'); + void x.replace(/X/g, 'ZZ'); + void x.replace(/X/g, 'ZZ'); + void x.replace(/X/g, 'ZZ'); + void x.replace(/X/g, 'ZZ'); + void x.replace(/X/g, 'ZZ'); + void x.replace(/X/g, 'ZZ'); + void x.replace(/X/g, 'ZZ'); + void x.replace(/X/g, 'ZZ'); + void x.replace(/X/g, 'ZZ'); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-replace-nonbmp-1.js b/tests/perf/test-string-replace-nonbmp-1.js new file mode 100644 index 00000000..d27c9e06 --- /dev/null +++ b/tests/perf/test-string-replace-nonbmp-1.js @@ -0,0 +1,29 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var i; + var x; + + x = 'foobar\u{1f4a9}'.repeat(1000); + console.log(x); + + for (i = 0; i < 1e5; i++) { + void x.replace('\ud83d', 'XX'); + void x.replace('\ud83d', 'XX'); + void x.replace('\ud83d', 'XX'); + void x.replace('\ud83d', 'XX'); + void x.replace('\ud83d', 'XX'); + void x.replace('\ud83d', 'XX'); + void x.replace('\ud83d', 'XX'); + void x.replace('\ud83d', 'XX'); + void x.replace('\ud83d', 'XX'); + void x.replace('\ud83d', 'XX'); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-replace-nonbmp-2.js b/tests/perf/test-string-replace-nonbmp-2.js new file mode 100644 index 00000000..bb615e40 --- /dev/null +++ b/tests/perf/test-string-replace-nonbmp-2.js @@ -0,0 +1,29 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var i; + var x; + + x = 'foobar\u{1f4a9}'.repeat(1000); + console.log(x); + + for (i = 0; i < 5e2; i++) { + void x.replace(/\ud83d/g, 'XX'); + void x.replace(/\ud83d/g, 'XX'); + void x.replace(/\ud83d/g, 'XX'); + void x.replace(/\ud83d/g, 'XX'); + void x.replace(/\ud83d/g, 'XX'); + void x.replace(/\ud83d/g, 'XX'); + void x.replace(/\ud83d/g, 'XX'); + void x.replace(/\ud83d/g, 'XX'); + void x.replace(/\ud83d/g, 'XX'); + void x.replace(/\ud83d/g, 'XX'); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-scan-nonascii-long.js b/tests/perf/test-string-scan-nonascii-long.js new file mode 100644 index 00000000..4343bcfa --- /dev/null +++ b/tests/perf/test-string-scan-nonascii-long.js @@ -0,0 +1,50 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var str = []; + var i; + + for (i = 0; i < 65536; i++) { + str.push(i & 0xffff); + } + str = String.fromCharCode.apply(null, str).repeat(64); + print(str.length); + + /* Because this testcase is not about interning, intern the substrings + * to avoid string table traffic in this particular test. + */ + var dummy = [ + str.charAt(0), + str.charAt(2023000), + str.charAt(100000), + str.charAt(200000), + str.charAt(300000), + str.charAt(400000), + str.charAt(900000), + str.charAt(800000), + str.charAt(700000), + str.charAt(600000), + str.charAt(500000) + ]; + + for (i = 0; i < 500; i++) { + void str.charCodeAt(0); + void str.charCodeAt(2023000); + void str.charCodeAt(100000); + void str.charCodeAt(200000); + void str.charCodeAt(300000); + void str.charCodeAt(400000); + void str.charCodeAt(900000); + void str.charCodeAt(800000); + void str.charCodeAt(700000); + void str.charCodeAt(600000); + void str.charCodeAt(500000); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-scan-nonascii.js b/tests/perf/test-string-scan-nonascii.js index a2481451..812c96be 100644 --- a/tests/perf/test-string-scan-nonascii.js +++ b/tests/perf/test-string-scan-nonascii.js @@ -11,17 +11,17 @@ function test() { * to avoid string table traffic in this particular test. */ var dummy = [ - str.charCodeAt(0), - str.charCodeAt(1023), - str.charCodeAt(100), - str.charCodeAt(200), - str.charCodeAt(300), - str.charCodeAt(400), - str.charCodeAt(900), - str.charCodeAt(800), - str.charCodeAt(700), - str.charCodeAt(600), - str.charCodeAt(500) + str.charAt(0), + str.charAt(1023), + str.charAt(100), + str.charAt(200), + str.charAt(300), + str.charAt(400), + str.charAt(900), + str.charAt(800), + str.charAt(700), + str.charAt(600), + str.charAt(500) ]; for (i = 0; i < 1e6; i++) { diff --git a/tests/perf/test-string-split-nonbmp-1.js b/tests/perf/test-string-split-nonbmp-1.js new file mode 100644 index 00000000..044f5583 --- /dev/null +++ b/tests/perf/test-string-split-nonbmp-1.js @@ -0,0 +1,29 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var i; + var x; + + x = 'foobar\u{1f4a9}'.repeat(1000); + console.log(x); + + for (i = 0; i < 1e4; i++) { + void x.split('\u{1f4a9}'); + void x.split('\u{1f4a9}'); + void x.split('\u{1f4a9}'); + void x.split('\u{1f4a9}'); + void x.split('\u{1f4a9}'); + void x.split('\u{1f4a9}'); + void x.split('\u{1f4a9}'); + void x.split('\u{1f4a9}'); + void x.split('\u{1f4a9}'); + void x.split('\u{1f4a9}'); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-startswith-ascii-1.js b/tests/perf/test-string-startswith-ascii-1.js new file mode 100644 index 00000000..31294b16 --- /dev/null +++ b/tests/perf/test-string-startswith-ascii-1.js @@ -0,0 +1,35 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var str = []; + var i; + + for (i = 0; i < 1024; i++) { + str.push(i & 0x7f); + } + str = String.fromCharCode.apply(null, str); + print(str.length); + + var prefix1 = str.substr(0, 10); + var prefix2 = prefix1 + '_'; // No match. + + for (i = 0; i < 1e6; i++) { + void str.startsWith(prefix1); + void str.startsWith(prefix2); + void str.startsWith(prefix1); + void str.startsWith(prefix2); + void str.startsWith(prefix1); + void str.startsWith(prefix2); + void str.startsWith(prefix1); + void str.startsWith(prefix2); + void str.startsWith(prefix1); + void str.startsWith(prefix2); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-startswith-nonascii-1.js b/tests/perf/test-string-startswith-nonascii-1.js new file mode 100644 index 00000000..8d49df1b --- /dev/null +++ b/tests/perf/test-string-startswith-nonascii-1.js @@ -0,0 +1,35 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var str = []; + var i; + + for (i = 0; i < 1024; i++) { + str.push(i & 0xffff); + } + str = String.fromCharCode.apply(null, str); + print(str.length); + + var prefix1 = str.substr(0, 10); + var prefix2 = prefix1 + '_'; // No match. + + for (i = 0; i < 1e6; i++) { + void str.startsWith(prefix1); + void str.startsWith(prefix2); + void str.startsWith(prefix1); + void str.startsWith(prefix2); + void str.startsWith(prefix1); + void str.startsWith(prefix2); + void str.startsWith(prefix1); + void str.startsWith(prefix2); + void str.startsWith(prefix1); + void str.startsWith(prefix2); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-substring-ascii-1.js b/tests/perf/test-string-substring-ascii-1.js new file mode 100644 index 00000000..18943eaa --- /dev/null +++ b/tests/perf/test-string-substring-ascii-1.js @@ -0,0 +1,33 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var str = []; + var i; + + for (i = 0; i < 1024; i++) { + str.push(i & 0x7f); + } + str = String.fromCharCode.apply(null, str); + print(str.length); + + var strlen = str.length; + for (i = 0; i < 1e5; i++) { + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-substring-ascii-2.js b/tests/perf/test-string-substring-ascii-2.js new file mode 100644 index 00000000..6a4e4d17 --- /dev/null +++ b/tests/perf/test-string-substring-ascii-2.js @@ -0,0 +1,33 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var str = []; + var i; + + for (i = 0; i < 65536; i++) { + str.push(i & 0x7f); + } + str = String.fromCharCode.apply(null, str); + print(str.length); + + var strlen = str.length; + for (i = 0; i < 5e4; i++) { + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-substring-ascii-3.js b/tests/perf/test-string-substring-ascii-3.js new file mode 100644 index 00000000..a914f849 --- /dev/null +++ b/tests/perf/test-string-substring-ascii-3.js @@ -0,0 +1,33 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var str = []; + var i; + + for (i = 0; i < 65536; i++) { + str.push(i & 0x7f); + } + str = String.fromCharCode.apply(null, str).repeat(16); // 1M codepoints + print(str.length); + + var strlen = str.length; + for (i = 0; i < 1e4; i++) { + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-substring-nonascii-1.js b/tests/perf/test-string-substring-nonascii-1.js new file mode 100644 index 00000000..e1ea35b8 --- /dev/null +++ b/tests/perf/test-string-substring-nonascii-1.js @@ -0,0 +1,33 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var str = []; + var i; + + for (i = 0; i < 1024; i++) { + str.push(i); + } + str = String.fromCharCode.apply(null, str); + print(str.length); + + var strlen = str.length; + for (i = 0; i < 1e5; i++) { + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-substring-nonascii-2.js b/tests/perf/test-string-substring-nonascii-2.js new file mode 100644 index 00000000..5e4a4686 --- /dev/null +++ b/tests/perf/test-string-substring-nonascii-2.js @@ -0,0 +1,33 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var str = []; + var i; + + for (i = 0; i < 65536; i++) { + str.push(i); + } + str = String.fromCharCode.apply(null, str); + print(str.length); + + var strlen = str.length; + for (i = 0; i < 2e3; i++) { + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-string-substring-nonascii-3.js b/tests/perf/test-string-substring-nonascii-3.js new file mode 100644 index 00000000..7c521a5e --- /dev/null +++ b/tests/perf/test-string-substring-nonascii-3.js @@ -0,0 +1,33 @@ +if (typeof print !== 'function') { print = console.log; } + +function test() { + var str = []; + var i; + + for (i = 0; i < 65536; i++) { + str.push(i); + } + str = String.fromCharCode.apply(null, str).repeat(16); // 1M codepoints + print(str.length); + + var strlen = str.length; + for (i = 0; i < 2e2; i++) { + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + void str.substring(Math.random() * strlen, Math.random() * strlen); + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +}