From 65ae1694c3a07f014d61794f1e1d17f841f67eec Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Mon, 19 Dec 2016 11:12:36 +0200 Subject: [PATCH] Add a few microbenchmarks for property caching --- tests/perf/test-prop-read-long-inherit.js | 20 +++++++++++++++++++ tests/perf/test-prop-read-math-pi.js | 14 +++++++++++++ tests/perf/test-prop-write-long-inherit.js | 23 ++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 tests/perf/test-prop-read-long-inherit.js create mode 100644 tests/perf/test-prop-read-math-pi.js create mode 100644 tests/perf/test-prop-write-long-inherit.js diff --git a/tests/perf/test-prop-read-long-inherit.js b/tests/perf/test-prop-read-long-inherit.js new file mode 100644 index 0000000000..e8f93f1963 --- /dev/null +++ b/tests/perf/test-prop-read-long-inherit.js @@ -0,0 +1,20 @@ +function test() { + var i; + var obj; + + obj = { foo: 123 }; + for (i = 0; i < 100; i++) { + obj = Object.create(obj); +  } + + for (i = 0; i < 1e7; i++) { + void obj.foo; + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-prop-read-math-pi.js b/tests/perf/test-prop-read-math-pi.js new file mode 100644 index 0000000000..7cb2111b73 --- /dev/null +++ b/tests/perf/test-prop-read-math-pi.js @@ -0,0 +1,14 @@ +function test() { + var i; + + for (i = 0; i < 1e7; i++) { + void Math.PI + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +} diff --git a/tests/perf/test-prop-write-long-inherit.js b/tests/perf/test-prop-write-long-inherit.js new file mode 100644 index 0000000000..174ec7f3b0 --- /dev/null +++ b/tests/perf/test-prop-write-long-inherit.js @@ -0,0 +1,23 @@ +function test() { + var i; + var obj; + + obj = { foo: 123 }; + for (i = 0; i < 100; i++) { + obj = Object.create(obj); +  } + + for (i = 0; i < 1e7; i++) { + // Because a write always causes an own property to be created, + // there's no difference between a shallow and deep object except + // on the very first write. + obj.foo = 123; + } +} + +try { + test(); +} catch (e) { + print(e.stack || e); + throw e; +}