From 6789c3f9df4dee4450fc8d741f1e0f2b155617f1 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Tue, 27 Dec 2016 04:23:35 +0200 Subject: [PATCH] Add some initial memory tests These can be executed using valgrind --tool=massif to get a rough idea of memory behavior. Valgrind massif using libc allocation primitives does carry overhead that a proper pool allocator doesn't (they can be made overhead free); but these numbers are still useful as guides. --- tests/memory/test-function-expression-1.js | 8 ++++++++ tests/memory/test-function-expression-2.js | 11 +++++++++++ tests/memory/test-plain-buffer-1.js | 8 ++++++++ tests/memory/test-uint8array-1.js | 8 ++++++++ 4 files changed, 35 insertions(+) create mode 100644 tests/memory/test-function-expression-1.js create mode 100644 tests/memory/test-function-expression-2.js create mode 100644 tests/memory/test-plain-buffer-1.js create mode 100644 tests/memory/test-uint8array-1.js diff --git a/tests/memory/test-function-expression-1.js b/tests/memory/test-function-expression-1.js new file mode 100644 index 0000000000..39b3f42b24 --- /dev/null +++ b/tests/memory/test-function-expression-1.js @@ -0,0 +1,8 @@ +function test() { + var arr = []; + while (arr.length < 1e5) { + arr.push(function () {}); + } + print(arr.length + ' anonymous functions created'); +} +test(); diff --git a/tests/memory/test-function-expression-2.js b/tests/memory/test-function-expression-2.js new file mode 100644 index 0000000000..66098d4ab3 --- /dev/null +++ b/tests/memory/test-function-expression-2.js @@ -0,0 +1,11 @@ +function test() { + var arr = []; + var fn; + while (arr.length < 1e4) { + fn = function () {}; + fn.prototype = null; + arr.push(fn); + } + print(arr.length + ' anonymous functions created'); +} +test(); diff --git a/tests/memory/test-plain-buffer-1.js b/tests/memory/test-plain-buffer-1.js new file mode 100644 index 0000000000..1f1ecef86a --- /dev/null +++ b/tests/memory/test-plain-buffer-1.js @@ -0,0 +1,8 @@ +function test() { + var arr = []; + while (arr.length < 1e5) { + arr.push(Uint8Array.allocPlain(256)); + } + print(arr.length + ' plain buffers created'); +} +test(); diff --git a/tests/memory/test-uint8array-1.js b/tests/memory/test-uint8array-1.js new file mode 100644 index 0000000000..487818986d --- /dev/null +++ b/tests/memory/test-uint8array-1.js @@ -0,0 +1,8 @@ +function test() { + var arr = []; + while (arr.length < 1e5) { + arr.push(new Uint8Array(256)); + } + print(arr.length + ' Uint8Arrays created'); +} +test();