From 2b128305a76e9315986eacb2516b18ea53cd9876 Mon Sep 17 00:00:00 2001 From: Zipdox Date: Thu, 11 May 2023 14:39:56 +0200 Subject: [PATCH] Use correct binary prefixes --- README.md | 4 ++-- pee.cjs | 6 +++--- pee.js | 6 +++--- test/pee.test.cjs | 28 ++++++++++++++-------------- test/pee.test.js | 28 ++++++++++++++-------------- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index a37c778..321e7da 100644 --- a/README.md +++ b/README.md @@ -19,14 +19,14 @@ npm install --save pee.js ### Ecmascript (pee.js) ```js import { leak } from 'pee.js'; -leak(69); // Leaks 69 MB of memory +leak(69); // Leaks 69 MiB of memory ``` See `test/pee.test.js` for a more in-depth example ### Commonjs (pee.cjs) ```js const { leak } = require('pee.js'); -leak(420); // Leaks 420 MB of memory +leak(420); // Leaks 420 MiB of memory ``` See `test/pee.test.cjs` for a more in-depth example diff --git a/pee.cjs b/pee.cjs index 949c74f..e46dd6c 100644 --- a/pee.cjs +++ b/pee.cjs @@ -1,12 +1,12 @@ // Take a leak -function leak(mb) { +function leak(mib) { // Fill the toilet with pee if (typeof window === "undefined") { // A global toilet is used to make it harder for the poor garbage men to clean up all the pee - global.toilet = new Uint8Array(Math.floor(mb * 1024 * 1024)).fill(69); + global.toilet = new Uint8Array(Math.floor(mib * 1024 * 1024)).fill(69); } else { // Pissing on someones windows will definitely be hard to clean up - window.toilet = new Uint8Array(Math.floor(mb * 1024 * 1024)).fill(69); + window.toilet = new Uint8Array(Math.floor(mib * 1024 * 1024)).fill(69); } // The 69 is (the number of the beast - thanks github copilit) // The 69 is also one of the fastest numbers I could fill the array with, tested on https://jsbench.me/z9l1b0ttf6 diff --git a/pee.js b/pee.js index b83339c..6a50143 100644 --- a/pee.js +++ b/pee.js @@ -1,12 +1,12 @@ // Take a leak and share it with the world -export function leak(mb) { +export function leak(mib) { // Fill the toilet with pee if (typeof window === "undefined") { // A global toilet is used to make it harder for the poor garbage men to clean up all the pee - global.toilet = new Uint8Array(Math.floor(mb * 1024 * 1024)).fill(69); + global.toilet = new Uint8Array(Math.floor(mib * 1024 * 1024)).fill(69); } else { // Pissing on someones windows will definitely be hard to clean up - window.toilet = new Uint8Array(Math.floor(mb * 1024 * 1024)).fill(69); + window.toilet = new Uint8Array(Math.floor(mib * 1024 * 1024)).fill(69); } // The 69 is (the number of the beast - thanks github copilit) // The 69 is also one of the fastest numbers I could fill the array with, tested on https://jsbench.me/z9l1b0ttf6 diff --git a/test/pee.test.cjs b/test/pee.test.cjs index f4d3ed5..3da3d1a 100644 --- a/test/pee.test.cjs +++ b/test/pee.test.cjs @@ -1,7 +1,7 @@ const { leak } = require('../pee.cjs'); -let getMemoryMB = () => process.memoryUsage().rss / 1024 / 1024; -let getArrayBufferMemoryMB = () => process.memoryUsage().arrayBuffers / 1024 / 1024; +let getMemoryMiB = () => process.memoryUsage().rss / 1024 / 1024; +let getArrayBufferMemoryMiB = () => process.memoryUsage().arrayBuffers / 1024 / 1024; const amountOfPee = 10; const margin = .95; @@ -9,36 +9,36 @@ const margin = .95; test('it can pee', (andMakesSureThereIsNoLastDrop) => { console.log('Testing commonjs'); - let initiallyUsed = getMemoryMB(); - let initiallyUsedArrayBuffers = getArrayBufferMemoryMB(); + let initiallyUsed = getMemoryMiB(); + let initiallyUsedArrayBuffers = getArrayBufferMemoryMiB(); - console.log(`The script uses approximately ${initiallyUsed.toFixed(2)} MB of total memory before Peeing.`); - console.log(`The script uses approximately ${initiallyUsedArrayBuffers.toFixed(2)} MB of ArrayBuffer memory before Peeing.`); + console.log(`The script uses approximately ${initiallyUsed.toFixed(2)} MiB of total memory before Peeing.`); + console.log(`The script uses approximately ${initiallyUsedArrayBuffers.toFixed(2)} MiB of ArrayBuffer memory before Peeing.`); leak(amountOfPee); - let used = getMemoryMB(); + let used = getMemoryMiB(); let peeDifferential = used - initiallyUsed; - let usedArrayBuffers = getArrayBufferMemoryMB(); + let usedArrayBuffers = getArrayBufferMemoryMiB(); let peeDifferentialArrayBuffers = usedArrayBuffers - initiallyUsedArrayBuffers; - console.log(`The script uses approximately ${used.toFixed(2)} MB of total memory after Peeing.`); - console.log(`The script uses approximately ${usedArrayBuffers.toFixed(2)} MB of ArrayBuffers after Peeing.`); + console.log(`The script uses approximately ${used.toFixed(2)} MiB of total memory after Peeing.`); + console.log(`The script uses approximately ${usedArrayBuffers.toFixed(2)} MiB of ArrayBuffers after Peeing.`); expect(peeDifferentialArrayBuffers >= amountOfPee * margin).toBeTruthy(); console.log("Waiting 10 seconds..."); setTimeout(() => { - used = getMemoryMB(); + used = getMemoryMiB(); peeDifferential = used - initiallyUsed; - usedArrayBuffers = getArrayBufferMemoryMB(); + usedArrayBuffers = getArrayBufferMemoryMiB(); peeDifferentialArrayBuffers = usedArrayBuffers - initiallyUsedArrayBuffers; - console.log(`The script uses approximately ${used.toFixed(2)} MB of total memory 10 seconds after Peeing.`); - console.log(`The script uses approximately ${usedArrayBuffers.toFixed(2)} MB of ArrayBuffers 10 seconds after Peeing.`); + console.log(`The script uses approximately ${used.toFixed(2)} MiB of total memory 10 seconds after Peeing.`); + console.log(`The script uses approximately ${usedArrayBuffers.toFixed(2)} MiB of ArrayBuffers 10 seconds after Peeing.`); expect(peeDifferentialArrayBuffers >= amountOfPee * margin).toBeTruthy(); diff --git a/test/pee.test.js b/test/pee.test.js index 9866681..86a8229 100644 --- a/test/pee.test.js +++ b/test/pee.test.js @@ -1,7 +1,7 @@ import { leak } from '../pee.js'; -let getMemoryMB = () => process.memoryUsage().rss / 1024 / 1024; -let getArrayBufferMemoryMB = () => process.memoryUsage().arrayBuffers / 1024 / 1024; +let getMemoryMiB = () => process.memoryUsage().rss / 1024 / 1024; +let getArrayBufferMemoryMiB = () => process.memoryUsage().arrayBuffers / 1024 / 1024; const amountOfPee = 10; const margin = .95; @@ -9,36 +9,36 @@ const margin = .95; test('it can pee', (andMakesSureThereIsNoLastDrop) => { console.log('Testing commonjs'); - let initiallyUsed = getMemoryMB(); - let initiallyUsedArrayBuffers = getArrayBufferMemoryMB(); + let initiallyUsed = getMemoryMiB(); + let initiallyUsedArrayBuffers = getArrayBufferMemoryMiB(); - console.log(`The script uses approximately ${initiallyUsed.toFixed(2)} MB of total memory before Peeing.`); - console.log(`The script uses approximately ${initiallyUsedArrayBuffers.toFixed(2)} MB of ArrayBuffer memory before Peeing.`); + console.log(`The script uses approximately ${initiallyUsed.toFixed(2)} MiB of total memory before Peeing.`); + console.log(`The script uses approximately ${initiallyUsedArrayBuffers.toFixed(2)} MiB of ArrayBuffer memory before Peeing.`); leak(amountOfPee); - let used = getMemoryMB(); + let used = getMemoryMiB(); let peeDifferential = used - initiallyUsed; - let usedArrayBuffers = getArrayBufferMemoryMB(); + let usedArrayBuffers = getArrayBufferMemoryMiB(); let peeDifferentialArrayBuffers = usedArrayBuffers - initiallyUsedArrayBuffers; - console.log(`The script uses approximately ${used.toFixed(2)} MB of total memory after Peeing.`); - console.log(`The script uses approximately ${usedArrayBuffers.toFixed(2)} MB of ArrayBuffers after Peeing.`); + console.log(`The script uses approximately ${used.toFixed(2)} MiB of total memory after Peeing.`); + console.log(`The script uses approximately ${usedArrayBuffers.toFixed(2)} MiB of ArrayBuffers after Peeing.`); expect(peeDifferentialArrayBuffers >= amountOfPee * margin).toBeTruthy(); console.log("Waiting 10 seconds..."); setTimeout(() => { - used = getMemoryMB(); + used = getMemoryMiB(); peeDifferential = used - initiallyUsed; - usedArrayBuffers = getArrayBufferMemoryMB(); + usedArrayBuffers = getArrayBufferMemoryMiB(); peeDifferentialArrayBuffers = usedArrayBuffers - initiallyUsedArrayBuffers; - console.log(`The script uses approximately ${used.toFixed(2)} MB of total memory 10 seconds after Peeing.`); - console.log(`The script uses approximately ${usedArrayBuffers.toFixed(2)} MB of ArrayBuffers 10 seconds after Peeing.`); + console.log(`The script uses approximately ${used.toFixed(2)} MiB of total memory 10 seconds after Peeing.`); + console.log(`The script uses approximately ${usedArrayBuffers.toFixed(2)} MiB of ArrayBuffers 10 seconds after Peeing.`); expect(peeDifferentialArrayBuffers >= amountOfPee * margin).toBeTruthy();