Skip to content

Commit

Permalink
fix(benchmark-test): suggestions for #10975
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Feb 11, 2025
1 parent e32d54c commit 81edfc5
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 98 deletions.
1 change: 1 addition & 0 deletions packages/agoric-cli/src/sdk-package-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default [
"@agoric/async-flow",
"@agoric/base-zone",
"@agoric/benchmark",
"@agoric/benchmark-test",
"@agoric/boot",
"@agoric/builders",
"@agoric/cache",
Expand Down
35 changes: 0 additions & 35 deletions packages/benchmark-test/benchmark.js

This file was deleted.

49 changes: 0 additions & 49 deletions packages/benchmark-test/benchmark.test.js

This file was deleted.

32 changes: 25 additions & 7 deletions packages/benchmark-test/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
{
"name": "benchmark",
"version": "1.0.0",
"type": "module",
"scripts": {
"test": "yarn rollup -c && eshost -h v8,xs dist/bundle.js"
},
"license": "MIT"
"name": "@agoric/benchmark-test",
"version": "1.0.0",
"type": "module",
"scripts": {
"build": "exit 0",
"prepack": "tsc --build tsconfig.build.json",
"postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'",
"test": "yarn rollup -c && eshost -h 'V8,Moddable XS' dist/bundle.js",
"lint": "run-s --continue-on-error lint:*",
"lint:eslint": "eslint .",
"lint:types": "tsc"
},
"author": "Agoric",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/Agoric/agoric-sdk/issues"
},
"homepage": "https://github.com/Agoric/agoric-sdk#readme",
"devDependencies": {
"tsd": "^0.31.1",
"@rollup/plugin-node-resolve": "^16.0.0",
"@rollup/plugin-commonjs": "^28.0.2",
"@endo/init": "^1.1.8",
"@endo/pass-style": "^1.4.8"
}
}
8 changes: 2 additions & 6 deletions packages/benchmark-test/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';

export default {
input: 'benchmark.test.js',
input: 'test/benchmark.test.js',
output: {
file: 'dist/bundle.js',
format: 'iife',
name: 'bundle',
sourcemap: false,
},
plugins: [
resolve(),
commonjs(),
],
plugins: [resolve(), commonjs()],
};

58 changes: 58 additions & 0 deletions packages/benchmark-test/test/benchmark.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import '@endo/init';
import { passStyleOf } from '@endo/pass-style';
import { test, benchmark } from '../tools/benchmark.js';

async function runBenchmark() {
await test('Benchmark', async t => {
await benchmark(
'Empty object',
t,
async () => {
passStyleOf(harden({}));
},
0.01,
);
});

await test('Another Benchmark', async t => {
await benchmark(
'Alphabets object',
t,
async () => {
passStyleOf(
harden({
a: 12,
b: 13,
c: 14,
d: 15,
e: 16,
f: 17,
g: 18,
h: 19,
i: 20,
j: 21,
k: 22,
l: 23,
m: 24,
n: 25,
o: 26,
p: 27,
q: 28,
r: 29,
s: 30,
t: 31,
u: 32,
v: 33,
w: 34,
x: 35,
y: 36,
z: 37,
}),
);
},
0.001,
);
});
}

void runBenchmark();
39 changes: 39 additions & 0 deletions packages/benchmark-test/tools/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// import { performance } from 'perf_hooks';
const performance = { now: () => Date.now() };

async function benchmark(name, t, fn, expedtedTime, iterations = 10000) {
await null;
const start = performance.now(); // 3
for (let i = 0; i < iterations; i += 1) {
await fn();
}
const end = performance.now(); // 8
const avgTime = (end - start) / iterations;

console.log(`${name} | Average time: ${avgTime}ms`);
t.assert(
avgTime < expedtedTime,
`Expected ${avgTime} to be less than ${expedtedTime}`,
);
}

async function test(name, fn) {
await null;
try {
console.log('Running test: ', name);
await fn({ assert, truthy });
console.log(`✅ Passed`);
} catch (err) {
console.log(`❌ Failed: ${err.message}`);
}
}

function assert(condition, message = 'Assertion failed') {
if (!condition) throw new Error(message);
}

function truthy(value, message = 'Expected a truthy value') {
if (!value) throw new Error(message);
}

export { benchmark, test };
6 changes: 6 additions & 0 deletions packages/benchmark-test/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": [
"./tsconfig.json",
"../../tsconfig-build-options.json"
]
}
10 changes: 10 additions & 0 deletions packages/benchmark-test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This file can contain .js-specific Typescript compiler config.
{
"extends": "../../tsconfig.json",
"compilerOptions": {},
"include": [
"tools",
"test",
"rollup.config.js"
]
}
12 changes: 12 additions & 0 deletions packages/benchmark-test/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": [
"../../typedoc.base.json"
],
"entryPoints": [
"tools/benchmark.js"
],
"validation": {
"notExported": false,
"invalidLink": false,
}
}
Loading

0 comments on commit 81edfc5

Please # to comment.