Skip to content

Commit

Permalink
Use correct binary prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zipdox committed May 11, 2023
1 parent 283a46e commit 2b12830
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions pee.cjs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions pee.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 14 additions & 14 deletions test/pee.test.cjs
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
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;

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();

Expand Down
28 changes: 14 additions & 14 deletions test/pee.test.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
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;

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();

Expand Down

0 comments on commit 2b12830

Please sign in to comment.