Browse Source

Merge pull request #2352 from svaarala/prop-perf-tests

Perf test additions
pull/2354/head
Sami Vaarala 4 years ago
committed by GitHub
parent
commit
757f48a686
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      tests/perf/test-add-int-constfold-left.js
  2. 27
      tests/perf/test-add-int-constfold-right.js
  3. 24
      tests/perf/test-array-grow-assign.js
  4. 24
      tests/perf/test-array-grow-push.js
  5. 28
      tests/perf/test-buffer-float32array-read.js
  6. 28
      tests/perf/test-buffer-uint8array-read.js
  7. 28
      tests/perf/test-buffer-uint8array-write.js
  8. 2
      tests/perf/test-json-serialize-jsonrpc-message.js
  9. 22
      tests/perf/test-object-assign-large.js
  10. 23
      tests/perf/test-object-deep-inherit-lookup.js
  11. 27
      tests/perf/test-object-deep-inherit.js
  12. 26
      tests/perf/test-object-deep-reference.js
  13. 22
      tests/perf/test-object-freeze.js
  14. 22
      tests/perf/test-object-seal.js
  15. 37
      tests/perf/test-prop-def-existing-multiple.js
  16. 4
      tests/perf/test-prop-read-all-n.js
  17. 35
      tests/perf/test-prop-read-inherited-arridx.js
  18. 35
      tests/perf/test-prop-read-inherited-u8array.js
  19. 33
      tests/perf/test-prop-write-all-n.js
  20. 30
      tests/perf/test-prop-write-array-existing.js
  21. 33
      tests/perf/test-prop-write-array-extend.js
  22. 40
      tests/perf/test-prop-write-inherited-arridx.js
  23. 36
      tests/perf/test-prop-write-inherited-u8array.js

27
tests/perf/test-add-int-constfold-left.js

@ -0,0 +1,27 @@
if (typeof print !== 'function') { print = console.log; }
function test() {
var i;
var x = 123;
var t;
for (i = 0; i < 1e7; i++) {
t = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + x;
t = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + x;
t = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + x;
t = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + x;
t = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + x;
t = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + x;
t = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + x;
t = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + x;
t = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + x;
t = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + x;
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

27
tests/perf/test-add-int-constfold-right.js

@ -0,0 +1,27 @@
if (typeof print !== 'function') { print = console.log; }
function test() {
var i;
var x = 123;
var t;
for (i = 0; i < 1e7; i++) {
t = x + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
t = x + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
t = x + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
t = x + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
t = x + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
t = x + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
t = x + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
t = x + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
t = x + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
t = x + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

24
tests/perf/test-array-grow-assign.js

@ -0,0 +1,24 @@
if (typeof print !== 'function') { print = console.log; }
function test() {
var i;
var arr;
for (i = 0; i < 1e4; i++) {
arr = [];
while (arr.length < 1e3) {
arr[arr.length] = 'foo'; arr[arr.length] = 'bar';
arr[arr.length] = 'foo'; arr[arr.length] = 'bar';
arr[arr.length] = 'foo'; arr[arr.length] = 'bar';
arr[arr.length] = 'foo'; arr[arr.length] = 'bar';
arr[arr.length] = 'foo'; arr[arr.length] = 'bar';
}
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

24
tests/perf/test-array-grow-push.js

@ -0,0 +1,24 @@
if (typeof print !== 'function') { print = console.log; }
function test() {
var i;
var arr;
for (i = 0; i < 1e4; i++) {
arr = [];
while (arr.length < 1e3) {
arr.push('foo'); arr.push('bar');
arr.push('foo'); arr.push('bar');
arr.push('foo'); arr.push('bar');
arr.push('foo'); arr.push('bar');
arr.push('foo'); arr.push('bar');
}
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

28
tests/perf/test-buffer-float32array-read.js

@ -0,0 +1,28 @@
if (typeof print !== 'function') { print = console.log; }
function test() {
var b = new Float32Array(4096);
var i;
print(typeof b);
for (i = 0; i < 1e7; i++) {
void b[100];
void b[100];
void b[100];
void b[100];
void b[100];
void b[100];
void b[100];
void b[100];
void b[100];
void b[100];
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

28
tests/perf/test-buffer-uint8array-read.js

@ -0,0 +1,28 @@
if (typeof print !== 'function') { print = console.log; }
function test() {
var b = new Uint8Array(4096);
var i;
print(typeof b);
for (i = 0; i < 1e7; i++) {
void b[100];
void b[100];
void b[100];
void b[100];
void b[100];
void b[100];
void b[100];
void b[100];
void b[100];
void b[100];
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

28
tests/perf/test-buffer-uint8array-write.js

@ -0,0 +1,28 @@
if (typeof print !== 'function') { print = console.log; }
function test() {
var b = new Uint8Array(4096);
var i;
print(typeof b);
for (i = 0; i < 1e7; i++) {
b[100] = 123;
b[100] = 123;
b[100] = 123;
b[100] = 123;
b[100] = 123;
b[100] = 123;
b[100] = 123;
b[100] = 123;
b[100] = 123;
b[100] = 123;
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

2
tests/perf/test-json-serialize-jsonrpc-message.js

@ -2,6 +2,8 @@
* Simulate creation and JSON serialization of a fake JSONRPC message.
*/
if (typeof print !== 'function') { print = console.log; }
function test() {
var i;
var msg;

22
tests/perf/test-object-assign-large.js

@ -0,0 +1,22 @@
if (typeof print !== 'function') { print = console.log; }
function test() {
var obj = {};
var i;
var oa = Object.assign;
for (i = 0; i < 1e4; i++) {
obj['prop-' + i] = 1;
}
for (i = 0; i < 1e3; i++) {
void oa({}, obj);
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

23
tests/perf/test-object-deep-inherit-lookup.js

@ -0,0 +1,23 @@
if (typeof print !== 'function') { print = console.log; }
function mkObj(n) {
var res = { foo: 123 };
while (--n > 0) {
res = Object.create(res);
void res.noSuchProperty; // simulate a _Finalizer lookup
}
return res;
}
function test() {
for (var i = 0; i < 100; i++) {
void mkObj(3000);
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

27
tests/perf/test-object-deep-inherit.js

@ -0,0 +1,27 @@
// When an object is garbage collected by Duktape, a finalizer
// lookup is performed. This lookup includes inheritance, so
// for very deep structures there are O(N^2) own property lookups
// as each level of the deep hierarchy is finalized.
if (typeof print !== 'function') { print = console.log; }
function mkObj(n) {
var res = { foo: 123 };
while (--n > 0) {
res = Object.create(res);
}
return res;
}
function test() {
for (var i = 0; i < 100; i++) {
void mkObj(3000);
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

26
tests/perf/test-object-deep-reference.js

@ -0,0 +1,26 @@
// Like test-object-deep-inherit.js but the object is deep via ordinary
// references (not [[Prototype]]) which has no O(N^2) effect for
// _Finalizer lookup.
if (typeof print !== 'function') { print = console.log; }
function mkObj(n) {
var res = { foo: 123 };
while (--n > 0) {
res = { ref: res };
}
return res;
}
function test() {
for (var i = 0; i < 100; i++) {
void mkObj(3000);
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

22
tests/perf/test-object-freeze.js

@ -0,0 +1,22 @@
if (typeof print !== 'function') { print = console.log; }
function test() {
var obj;
var i;
var of = Object.freeze;
for (i = 0; i < 1e6; i++) {
obj = { prop1: 1, prop2: 2, prop3: 3, prop4: 4, prop5: 5,
prop6: 6, prop7: 7, prop8: 8, prop9: 9, prop10: 10 };
of(obj);
obj = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
of(obj);
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

22
tests/perf/test-object-seal.js

@ -0,0 +1,22 @@
if (typeof print !== 'function') { print = console.log; }
function test() {
var obj;
var i;
var os = Object.seal;
for (i = 0; i < 1e6; i++) {
obj = { prop1: 1, prop2: 2, prop3: 3, prop4: 4, prop5: 5,
prop6: 6, prop7: 7, prop8: 8, prop9: 9, prop10: 10 };
os(obj);
obj = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
os(obj);
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

37
tests/perf/test-prop-def-existing-multiple.js

@ -0,0 +1,37 @@
if (typeof print !== 'function') { print = console.log; }
function test() {
var odp = Object.defineProperties;
var i;
var obj = { foo: 123, bar: 234, quux: 345 };
var arr = [ 1, 2, 3, 4 ];
var desc1 = { value: 1001, writable: false, enumerable: true, configurable: true };
var desc2 = { value: 1001 };
var descs1 = {
foo: desc1,
bar: desc1,
quux: desc1,
baz: desc1, // non-existent
quuux: desc2 // non-existent
};
var descs2 = {
0: desc2,
1: desc2,
2: desc2,
3: desc2,
4: desc2 // non-existent, causes abandon
};
for (i = 0; i < 1e5; i++) {
void odp(obj, descs1);
void odp(arr, descs2);
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

4
tests/perf/test-prop-read-all-n.js

@ -22,9 +22,9 @@ function test(n) {
try {
for (var i = 1; i <= 32; i++) {
var t_start = performance.now();
var t_start = typeof performance !== 'undefined' ? performance.now() : Date.now();
test(i);
var t_end = performance.now();
var t_end = typeof performance !== 'undefined' ? performance.now() : Date.now();
print(i, (t_end - t_start) / 1000);
}
} catch (e) {

35
tests/perf/test-prop-read-inherited-arridx.js

@ -0,0 +1,35 @@
/*
* Basic property read performance for an inherited property
*/
if (typeof print !== 'function') { print = console.log; }
function test() {
var root = { xxx1: 1, xxx2: 2, xxx3: 3, xxx4: 4, foo: 123, 1234: 'foo' };
var i;
var ign;
var obj = Object.create(root);
obj = Object.create(obj); // two levels of inheritance
if (typeof Duktape !== 'undefined') { Duktape.compact(root); Duktape.compact(obj); }
for (i = 0; i < 1e7; i++) {
ign = obj[1234];
ign = obj[1234];
ign = obj[1234];
ign = obj[1234];
ign = obj[1234];
ign = obj[1234];
ign = obj[1234];
ign = obj[1234];
ign = obj[1234];
ign = obj[1234];
}
print(ign);
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

35
tests/perf/test-prop-read-inherited-u8array.js

@ -0,0 +1,35 @@
/*
* Basic property read performance for an inherited Uint8Array property
*/
if (typeof print !== 'function') { print = console.log; }
function test() {
var root = new Uint8Array(10000);
var i;
var ign;
var obj = Object.create(root);
obj = Object.create(obj); // two levels of inheritance
if (typeof Duktape !== 'undefined') { Duktape.compact(root); Duktape.compact(obj); }
for (i = 0; i < 1e7; i++) {
ign = obj[1234];
ign = obj[1234];
ign = obj[1234];
ign = obj[1234];
ign = obj[1234];
ign = obj[1234];
ign = obj[1234];
ign = obj[1234];
ign = obj[1234];
ign = obj[1234];
}
print(ign);
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

33
tests/perf/test-prop-write-all-n.js

@ -0,0 +1,33 @@
if (typeof print !== 'function') { print = console.log; }
function test(n) {
var obj = {};
var i, count;
for (i = 0; i < n; i++) {
obj['prop' + i] = 1;
}
if (typeof Duktape !== 'undefined') { Duktape.compact(obj); }
var code = [];
code.push('(function (obj) { for (var count = 1e7; count > 0;) {');
for (i = 0; i < 100; i++) {
code.push('obj.prop' + (i % n) + '= 123;');
}
code.push('count -= 100;');
code.push('} })');
eval(code.join(''))(obj);
}
try {
for (var i = 1; i <= 32; i++) {
var t_start = typeof performance !== 'undefined' ? performance.now() : Date.now();
test(i);
var t_end = typeof performance !== 'undefined' ? performance.now() : Date.now();
print(i, (t_end - t_start) / 1000);
}
} catch (e) {
print(e.stack || e);
throw e;
}

30
tests/perf/test-prop-write-array-existing.js

@ -0,0 +1,30 @@
/*
* Basic property write performance, array index writes for existing indices
*/
if (typeof print !== 'function') { print = console.log; }
function test() {
var arr = [];
var i;
for (i = 0; i < 1e7; i++) {
arr[0] = 123;
arr[1] = 123;
arr[2] = 123;
arr[3] = 123;
arr[4] = 123;
arr[5] = 123;
arr[6] = 123;
arr[7] = 123;
arr[8] = 123;
arr[9] = 123;
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

33
tests/perf/test-prop-write-array-extend.js

@ -0,0 +1,33 @@
/*
* Basic property write performance, array index writes extending an array
*/
if (typeof print !== 'function') { print = console.log; }
function test() {
var arr = [];
var i;
var src = [];
src.push('(function () {');
src.push(' var i, j, arr;');
src.push(' for (i = 0; i < 1e6; i++) {');
src.push(' arr = [];');
for (i = 0; i < 100; i++) {
src.push(' arr[' + i + '] = 123;');
}
src.push(' }');
src.push('})');
src = src.join('\n');
//print(src);
var code = eval(src);
code();
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

40
tests/perf/test-prop-write-inherited-arridx.js

@ -0,0 +1,40 @@
/*
* Basic property write performance for an inherited property
*/
if (typeof print !== 'function') { print = console.log; }
function test() {
var root = {};
var i;
var ign;
var obj;
for (i = 0; i < 100; i++) {
root['prop' + i] = 123;
}
if (typeof Duktape !== 'undefined') { Duktape.compact(root); }
for (i = 0; i < 1e5; i++) {
obj = Object.create(Object.create(root)); // two levels of inheritance
// All of these will be misses, propagating up to root, then establishing a property.
obj[1000] = 1; obj[1001] = 1; obj[1002] = 1; obj[1003] = 1; obj[1004] = 1; obj[1005] = 1; obj[1006] = 1; obj[1007] = 1; obj[1008] = 1; obj[1009] = 1;
obj[1010] = 1; obj[1011] = 1; obj[1012] = 1; obj[1013] = 1; obj[1014] = 1; obj[1015] = 1; obj[1016] = 1; obj[1017] = 1; obj[1018] = 1; obj[1019] = 1;
obj[1020] = 1; obj[1021] = 1; obj[1022] = 1; obj[1023] = 1; obj[1024] = 1; obj[1025] = 1; obj[1026] = 1; obj[1027] = 1; obj[1028] = 1; obj[1029] = 1;
obj[1030] = 1; obj[1031] = 1; obj[1032] = 1; obj[1033] = 1; obj[1034] = 1; obj[1035] = 1; obj[1036] = 1; obj[1037] = 1; obj[1038] = 1; obj[1039] = 1;
obj[1040] = 1; obj[1041] = 1; obj[1042] = 1; obj[1043] = 1; obj[1044] = 1; obj[1045] = 1; obj[1046] = 1; obj[1047] = 1; obj[1048] = 1; obj[1049] = 1;
obj[1050] = 1; obj[1051] = 1; obj[1052] = 1; obj[1053] = 1; obj[1054] = 1; obj[1055] = 1; obj[1056] = 1; obj[1057] = 1; obj[1058] = 1; obj[1059] = 1;
obj[1060] = 1; obj[1061] = 1; obj[1062] = 1; obj[1063] = 1; obj[1064] = 1; obj[1065] = 1; obj[1066] = 1; obj[1067] = 1; obj[1068] = 1; obj[1069] = 1;
obj[1070] = 1; obj[1071] = 1; obj[1072] = 1; obj[1073] = 1; obj[1074] = 1; obj[1075] = 1; obj[1076] = 1; obj[1077] = 1; obj[1078] = 1; obj[1079] = 1;
obj[1080] = 1; obj[1081] = 1; obj[1082] = 1; obj[1083] = 1; obj[1084] = 1; obj[1085] = 1; obj[1086] = 1; obj[1087] = 1; obj[1088] = 1; obj[1089] = 1;
obj[1090] = 1; obj[1091] = 1; obj[1092] = 1; obj[1093] = 1; obj[1094] = 1; obj[1095] = 1; obj[1096] = 1; obj[1097] = 1; obj[1098] = 1; obj[1099] = 1;
}
print(ign);
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

36
tests/perf/test-prop-write-inherited-u8array.js

@ -0,0 +1,36 @@
/*
* Basic property write performance for an inherited property
*/
if (typeof print !== 'function') { print = console.log; }
function test() {
var root = new Uint8Array(10000);
var i;
var ign;
var obj;
if (typeof Duktape !== 'undefined') { Duktape.compact(root); }
for (i = 0; i < 1e5; i++) {
obj = Object.create(Object.create(root)); // two levels of inheritance
obj[1000] = 1; obj[1001] = 1; obj[1002] = 1; obj[1003] = 1; obj[1004] = 1; obj[1005] = 1; obj[1006] = 1; obj[1007] = 1; obj[1008] = 1; obj[1009] = 1;
obj[1010] = 1; obj[1011] = 1; obj[1012] = 1; obj[1013] = 1; obj[1014] = 1; obj[1015] = 1; obj[1016] = 1; obj[1017] = 1; obj[1018] = 1; obj[1019] = 1;
obj[1020] = 1; obj[1021] = 1; obj[1022] = 1; obj[1023] = 1; obj[1024] = 1; obj[1025] = 1; obj[1026] = 1; obj[1027] = 1; obj[1028] = 1; obj[1029] = 1;
obj[1030] = 1; obj[1031] = 1; obj[1032] = 1; obj[1033] = 1; obj[1034] = 1; obj[1035] = 1; obj[1036] = 1; obj[1037] = 1; obj[1038] = 1; obj[1039] = 1;
obj[1040] = 1; obj[1041] = 1; obj[1042] = 1; obj[1043] = 1; obj[1044] = 1; obj[1045] = 1; obj[1046] = 1; obj[1047] = 1; obj[1048] = 1; obj[1049] = 1;
obj[1050] = 1; obj[1051] = 1; obj[1052] = 1; obj[1053] = 1; obj[1054] = 1; obj[1055] = 1; obj[1056] = 1; obj[1057] = 1; obj[1058] = 1; obj[1059] = 1;
obj[1060] = 1; obj[1061] = 1; obj[1062] = 1; obj[1063] = 1; obj[1064] = 1; obj[1065] = 1; obj[1066] = 1; obj[1067] = 1; obj[1068] = 1; obj[1069] = 1;
obj[1070] = 1; obj[1071] = 1; obj[1072] = 1; obj[1073] = 1; obj[1074] = 1; obj[1075] = 1; obj[1076] = 1; obj[1077] = 1; obj[1078] = 1; obj[1079] = 1;
obj[1080] = 1; obj[1081] = 1; obj[1082] = 1; obj[1083] = 1; obj[1084] = 1; obj[1085] = 1; obj[1086] = 1; obj[1087] = 1; obj[1088] = 1; obj[1089] = 1;
obj[1090] = 1; obj[1091] = 1; obj[1092] = 1; obj[1093] = 1; obj[1094] = 1; obj[1095] = 1; obj[1096] = 1; obj[1097] = 1; obj[1098] = 1; obj[1099] = 1;
}
print(ign);
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}
Loading…
Cancel
Save