Skip to content
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
3 changes: 2 additions & 1 deletion packages/benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"prepack": "tsc --build tsconfig.build.json",
"install-engines": "./install-engines.sh",
"test": "./run-tests.sh",
"cpu-prof-test": "yarn rollup -c && node --jitless --cpu-prof dist/bundle.js"
"cpu-prof-test": "yarn rollup -c && node --jitless --cpu-prof dist/bundle.js",
"test:node": "yarn rollup -c && node dist/bundle.js"
},
"devDependencies": {
"@endo/init": "workspace:^",
Expand Down
12 changes: 11 additions & 1 deletion packages/benchmark/src/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global process */

const getTime = () => Date.now() * 1_000_000;

async function benchmark(name, t, fn, expedtedTime, iterations = 10000) {
Expand Down Expand Up @@ -25,15 +27,23 @@ function truthy(value, message = 'Expected a truthy value') {
if (!value) throw Error(message);
}

function logMemoryUsage(message = '') {
if (typeof process === 'undefined') return;
console.log(message, process.memoryUsage());
}

async function test(name, fn) {
await null;
console.log('\n\n');
console.log('Running test: ', name);
logMemoryUsage('Memory Usage Before Test: ');
try {
console.log('Running test: ', name);
await fn({ assert, truthy });
console.log(`✅ Passed`);
} catch (err) {
console.log(`❌ Failed: ${err.message}`);
}
logMemoryUsage('Memory Usage After Test: ');
}

export { benchmark, test };
Loading