Browse Source

Perf test to exercise literal interning

pull/1810/head
Sami Vaarala 7 years ago
parent
commit
9b71032236
  1. 22
      tests/perf/test-func-tostring.js
  2. 35
      tests/perf/test-string-literal-intern.js
  3. 26
      tests/perf/test-symbol-tostring.js

22
tests/perf/test-func-tostring.js

@ -2,19 +2,19 @@ if (typeof print !== 'function') { print = console.log; }
function test() {
var fn = function foo() {};
var i, t;
var i;
for (i = 0; i < 1e6; i++) {
t = fn.toString();
t = fn.toString();
t = fn.toString();
t = fn.toString();
t = fn.toString();
t = fn.toString();
t = fn.toString();
t = fn.toString();
t = fn.toString();
t = fn.toString();
fn.toString();
fn.toString();
fn.toString();
fn.toString();
fn.toString();
fn.toString();
fn.toString();
fn.toString();
fn.toString();
fn.toString();
}
}

35
tests/perf/test-string-literal-intern.js

@ -0,0 +1,35 @@
/*
* Exercise the internal mechanism for intern checking a string literal
* pushed using e.g. duk_push_literal(). The ideal test target has a lot
* of literal interning and minimal other activity. No really good target
* exists now, but 'String(Buffer.prototype)' just pushes a literal and
* returns.
*/
if (typeof print !== 'function') { print = console.log; }
function test() {
var S = String;
var BP = Buffer.prototype;
var i;
for (i = 0; i < 1e5; i++) {
S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP);
S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP);
S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP);
S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP);
S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP);
S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP);
S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP);
S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP);
S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP);
S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP); S(BP);
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

26
tests/perf/test-symbol-tostring.js

@ -0,0 +1,26 @@
if (typeof print !== 'function') { print = console.log; }
function test() {
var S = Symbol('foo');
var i;
for (i = 0; i < 1e6; i++) {
String(S);
String(S);
String(S);
String(S);
String(S);
String(S);
String(S);
String(S);
String(S);
String(S);
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}
Loading…
Cancel
Save