-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(benchmark-test): suggestions for #10975
- Loading branch information
Showing
11 changed files
with
230 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": [ | ||
"./tsconfig.json", | ||
"../../tsconfig-build-options.json" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
Oops, something went wrong.