Browse Source

Add WTF-8 related perf tests

pull/2445/head
Sami Vaarala 3 years ago
parent
commit
e71e21c181
  1. 35
      tests/perf/test-string-endswith-ascii-1.js
  2. 35
      tests/perf/test-string-endswith-nonascii-1.js
  3. 29
      tests/perf/test-string-indexof-1.js
  4. 29
      tests/perf/test-string-lastindexof-1.js
  5. 42
      tests/perf/test-string-random-access-nonascii-long.js
  6. 42
      tests/perf/test-string-random-access-nonascii.js
  7. 29
      tests/perf/test-string-replace-ascii-1.js
  8. 29
      tests/perf/test-string-replace-ascii-2.js
  9. 29
      tests/perf/test-string-replace-nonbmp-1.js
  10. 29
      tests/perf/test-string-replace-nonbmp-2.js
  11. 50
      tests/perf/test-string-scan-nonascii-long.js
  12. 22
      tests/perf/test-string-scan-nonascii.js
  13. 29
      tests/perf/test-string-split-nonbmp-1.js
  14. 35
      tests/perf/test-string-startswith-ascii-1.js
  15. 35
      tests/perf/test-string-startswith-nonascii-1.js
  16. 33
      tests/perf/test-string-substring-ascii-1.js
  17. 33
      tests/perf/test-string-substring-ascii-2.js
  18. 33
      tests/perf/test-string-substring-ascii-3.js
  19. 33
      tests/perf/test-string-substring-nonascii-1.js
  20. 33
      tests/perf/test-string-substring-nonascii-2.js
  21. 33
      tests/perf/test-string-substring-nonascii-3.js

35
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;
}

35
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;
}

29
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;
}

29
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;
}

42
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;
}

42
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;
}

29
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;
}

29
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;
}

29
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;
}

29
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;
}

50
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;
}

22
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++) {

29
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;
}

35
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;
}

35
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;
}

33
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;
}

33
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;
}

33
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;
}

33
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;
}

33
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;
}

33
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;
}
Loading…
Cancel
Save