Browse Source

Array sort and Math.random() perf tests

pull/824/head
Sami Vaarala 8 years ago
parent
commit
7b35588ec8
  1. 26
      tests/perf/test-array-sort.js
  2. 30
      tests/perf/test-random.js

26
tests/perf/test-array-sort.js

@ -0,0 +1,26 @@
/*
* Array sort() test
*/
if (typeof print !== 'function') { print = console.log; }
function test() {
var arr = [];
var i, j;
var rnd = Math.random;
for (i = 0; i < 5; i++) {
for (j = 0; j < 10000; j++) {
arr[j] = rnd();
}
arr.sort();
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}

30
tests/perf/test-random.js

@ -0,0 +1,30 @@
/*
* Math.random() test
*/
if (typeof print !== 'function') { print = console.log; }
function test() {
var i;
var rnd = Math.random;
for (i = 0; i < 3e5; i++) {
rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd();
rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd();
rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd();
rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd();
rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd();
rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd();
rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd();
rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd();
rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd();
rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd(); rnd();
}
}
try {
test();
} catch (e) {
print(e.stack || e);
throw e;
}
Loading…
Cancel
Save