From 7b35588ec8e4908468e799df3915fd63474e1b74 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Tue, 13 Sep 2016 01:09:24 +0300 Subject: [PATCH] Array sort and Math.random() perf tests --- tests/perf/test-array-sort.js | 26 ++++++++++++++++++++++++++ tests/perf/test-random.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/perf/test-array-sort.js create mode 100644 tests/perf/test-random.js diff --git a/tests/perf/test-array-sort.js b/tests/perf/test-array-sort.js new file mode 100644 index 00000000..296a1e4d --- /dev/null +++ b/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; +} diff --git a/tests/perf/test-random.js b/tests/perf/test-random.js new file mode 100644 index 00000000..e88d4fca --- /dev/null +++ b/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; +}