Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct binary prefixes #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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