Browse Source

Perf testcases for JSON/JX

pull/447/head
Sami Vaarala 9 years ago
parent
commit
9e455b80d6
  1. 38
      tests/perf/test-json-serialize-forceslow.js
  2. 36
      tests/perf/test-jx-serialize-bufobj-forceslow.js
  3. 35
      tests/perf/test-jx-serialize-bufobj.js

38
tests/perf/test-json-serialize-forceslow.js

@ -0,0 +1,38 @@
if (typeof print !== 'function') { print = console.log; }
function build() {
var obj = {};
obj.key1 = 'foo';
obj.key2 = 'bar';
obj.key3 = 'quux';
obj.key4 = 'baz';
obj.key5 = 'quuux';
obj.key6 = [ 'foo', 'bar', 'quux', 'baz', 'quuux' ];
obj.key7 = [ undefined, null, true, 123.456, 1e200, {}, {}, {} ];
// Force to slow path (at least in Duktape 1.5.x):
// .toJSON() causes a bailout, but because the value
// is not callable it has no impact on the slow path.
Object.defineProperty(obj, 'toJSON', { value: 123, enumerable: false });
return obj;
}
function test() {
var obj;
var i;
var ignore;
obj = build();
for (i = 0; i < 4e5; i++) {
ignore = JSON.stringify(obj);
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

36
tests/perf/test-jx-serialize-bufobj-forceslow.js

@ -0,0 +1,36 @@
if (typeof print !== 'function') { print = console.log; }
function build() {
var obj = {};
var ab = new ArrayBuffer(32);
var vw = new Uint32Array(ab, 4, 3);
var i;
for (i = 0; i < ab.length; i++) {
ab[i] = i;
}
return {
foo: [ ab, ab, ab, ab, ab, ab, ab, ab, ab, ab, ab, ab, ab, ab, ab, ab ],
bar: [ vw, vw, vw, vw, vw, vw, vw, vw, vw, vw, vw, vw, vw, vw, vw, vw ],
toJSON: 123 // forces slow path in Duktape 1.5.x, but not called
};
}
function test() {
var obj;
var i;
var ignore;
obj = build();
for (i = 0; i < 3e5; i++) {
ignore = Duktape.enc('jx', obj);
}
//print(ignore);
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

35
tests/perf/test-jx-serialize-bufobj.js

@ -0,0 +1,35 @@
if (typeof print !== 'function') { print = console.log; }
function build() {
var obj = {};
var ab = new ArrayBuffer(32);
var vw = new Uint32Array(ab, 4, 3);
var i;
for (i = 0; i < ab.length; i++) {
ab[i] = i;
}
return {
foo: [ ab, ab, ab, ab, ab, ab, ab, ab, ab, ab, ab, ab, ab, ab, ab, ab ],
bar: [ vw, vw, vw, vw, vw, vw, vw, vw, vw, vw, vw, vw, vw, vw, vw, vw ]
};
}
function test() {
var obj;
var i;
var ignore;
obj = build();
for (i = 0; i < 3e5; i++) {
ignore = Duktape.enc('jx', obj);
}
//print(ignore);
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}
Loading…
Cancel
Save