Browse Source

a testcase which stresses object property set with random inserts and deletes

pull/1/head
Sami Vaarala 11 years ago
parent
commit
67e4a02c3c
  1. 52
      ecmascript-testcases/test-dev-propaccess-random.js

52
ecmascript-testcases/test-dev-propaccess-random.js

@ -0,0 +1,52 @@
/*
* Some stressing of object property insertion and deletion.
*/
/*===
0
1000000
2000000
3000000
4000000
5000000
6000000
7000000
8000000
9000000
===*/
function randomPropTest() {
var obj = {};
var i, j;
var k, v;
for (i = 0; i < 10000000; i++) {
if (i % 1000000 === 0) {
print(i);
//print(Duktape.jsonxEnc(obj));
}
k = Math.floor(Math.random() * 10000);
if (k < 1000) { k = k; }
else { k = "key-" + String(k); }
v = Math.floor(Math.random() * 100);
if (v < 10) { v = undefined; }
else if (v < 50) { v = i; }
else if (v < 80) { v = { foo: i }; }
else { v = "value-" + i; }
if (v === undefined) {
delete obj[k];
} else {
obj[k] = v;
}
}
}
try {
randomPropTest();
} catch (e) {
print(e);
}
Loading…
Cancel
Save