diff options
author | haturau <135221985+haturatu@users.noreply.github.com> | 2024-11-20 01:20:47 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-20 01:20:47 +0900 |
commit | 85719a67e59c7aa45bead26e4942d7df8b1b42d4 (patch) | |
tree | face0aecaac53e93ce2f23b53c48859bcf1a36ec /tests/specs/run/heapstats | |
parent | 67697bc2e4a62a9670699fd18ad0dd8efc5bd955 (diff) | |
parent | 186b52731c6bb326c4d32905c5e732d082e83465 (diff) |
Merge branch 'denoland:main' into main
Diffstat (limited to 'tests/specs/run/heapstats')
-rw-r--r-- | tests/specs/run/heapstats/__test__.jsonc | 4 | ||||
-rw-r--r-- | tests/specs/run/heapstats/heapstats.js | 37 | ||||
-rw-r--r-- | tests/specs/run/heapstats/heapstats.js.out | 2 |
3 files changed, 43 insertions, 0 deletions
diff --git a/tests/specs/run/heapstats/__test__.jsonc b/tests/specs/run/heapstats/__test__.jsonc new file mode 100644 index 000000000..6429d7cf5 --- /dev/null +++ b/tests/specs/run/heapstats/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "run --quiet --v8-flags=--expose-gc heapstats.js", + "output": "heapstats.js.out" +} diff --git a/tests/specs/run/heapstats/heapstats.js b/tests/specs/run/heapstats/heapstats.js new file mode 100644 index 000000000..b93c9c120 --- /dev/null +++ b/tests/specs/run/heapstats/heapstats.js @@ -0,0 +1,37 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +"use strict"; + +function allocTest(alloc, allocAssert, deallocAssert) { + // Helper func that GCs then returns memory usage + const sample = () => { + // deno-lint-ignore no-undef + gc(); + return Deno.memoryUsage(); + }; + const delta = (t1, t2) => t2.heapUsed - t1.heapUsed; + + // Sample "clean" heap usage + const t1 = sample(); + + // Alloc + // deno-lint-ignore no-unused-vars + let x = alloc(); + const t2 = sample(); + allocAssert(delta(t1, t2)); + + // Free + x = null; + const t3 = sample(); + deallocAssert(delta(t2, t3)); +} + +function main() { + // Large-array test, 1M slot array consumes ~4MB (4B per slot) + allocTest( + () => new Array(1e6), + (delta) => console.log("Allocated:", Math.round(delta / 1e6) + "MB"), + (delta) => console.log("Freed:", Math.round(delta / 1e6) + "MB"), + ); +} + +main(); diff --git a/tests/specs/run/heapstats/heapstats.js.out b/tests/specs/run/heapstats/heapstats.js.out new file mode 100644 index 000000000..954266333 --- /dev/null +++ b/tests/specs/run/heapstats/heapstats.js.out @@ -0,0 +1,2 @@ +Allocated: 8MB +Freed: -8MB |