-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update benchmarks to use mitata library instead of cronometro * Move benchmarks to a separate BENCHMARKS.md file, add benchmark:update to generate it * Fix verify benchmark: bad test PS512 token
- Loading branch information
1 parent
ffc1b8c
commit ce5b923
Showing
9 changed files
with
676 additions
and
262 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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,32 +1,14 @@ | ||
'use strict' | ||
|
||
import { isMainThread } from 'worker_threads' | ||
|
||
import { tokens, privateKeys, publicKeys, compareSigning, compareVerifying, saveLogs } from './utils.mjs' | ||
|
||
async function runSuites() { | ||
if (!isMainThread) { | ||
const algorightm = process.env.CURRENT_ALGORITHM | ||
|
||
if (process.env.CURRENT_PHASE === 'sign') { | ||
compareSigning({ a: 1, b: 2, c: 3 }, algorightm, privateKeys[algorightm], publicKeys[algorightm]) | ||
} else { | ||
compareVerifying(tokens[algorightm], algorightm, publicKeys[algorightm]) | ||
} | ||
|
||
return | ||
} else { | ||
for (const algorightm of ['HS256', 'RS256']) { | ||
process.env.CURRENT_ALGORITHM = algorightm | ||
|
||
process.env.CURRENT_PHASE = 'sign' | ||
await compareSigning({ a: 1, b: 2, c: 3 }, algorightm, privateKeys[algorightm], publicKeys[algorightm]) | ||
process.env.CURRENT_PHASE = 'verify' | ||
await compareVerifying(tokens[algorightm], algorightm, publicKeys[algorightm]) | ||
} | ||
for (const algorithm of ['HS256', 'RS256']) { | ||
await compareSigning({ a: 1, b: 2, c: 3 }, algorithm, privateKeys[algorithm], publicKeys[algorithm]) | ||
await compareVerifying(tokens[algorithm], algorithm, publicKeys[algorithm]) | ||
} | ||
|
||
await saveLogs('auth0') | ||
} | ||
|
||
runSuites().catch(console.error) | ||
await runSuites() |
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 |
---|---|---|
@@ -1,21 +1,16 @@ | ||
'use strict' | ||
|
||
import { isMainThread } from 'worker_threads' | ||
import { privateKeys, publicKeys, compareSigning, saveLogs } from './utils.mjs' | ||
|
||
async function runSuites() { | ||
if (!isMainThread) { | ||
const algorightm = process.env.CURRENT_ALGORITHM | ||
compareSigning({ a: 1, b: 2, c: 3 }, algorightm, privateKeys[algorightm], publicKeys[algorightm]) | ||
return | ||
} else { | ||
for (const algorightm of ['HS512', 'ES512', 'RS512', 'PS512', 'EdDSA']) { | ||
process.env.CURRENT_ALGORITHM = algorightm | ||
await compareSigning({ a: 1, b: 2, c: 3 }, algorightm, privateKeys[algorightm], publicKeys[algorightm]) | ||
} | ||
export async function runSuites() { | ||
const benchmarkResults = [] | ||
for (const algorithm of ['HS512', 'ES512', 'RS512', 'PS512', 'EdDSA']) { | ||
const result = await compareSigning({ a: 1, b: 2, c: 3 }, algorithm, privateKeys[algorithm], publicKeys[algorithm]) | ||
benchmarkResults.push({ algorithm, result }) | ||
} | ||
|
||
await saveLogs('sign') | ||
return benchmarkResults | ||
} | ||
|
||
runSuites().catch(console.error) | ||
if (import.meta.filename === process.argv[1]) await runSuites() |
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,42 @@ | ||
import { runSuites as runSignSuites } from './sign.mjs' | ||
import { runSuites as runVerifySuites } from './verify.mjs' | ||
import { runSuites as runDecodeSuites } from './decode.mjs' | ||
import { writeFile } from 'fs/promises' | ||
import { join } from 'path' | ||
|
||
const signBenchmark = await runSignSuites().catch(console.error) | ||
const decodeBenchmark = await runDecodeSuites().catch(console.error) | ||
const verifyBenchmark = await runVerifySuites().catch(console.error) | ||
|
||
const printDetail = ({ algorithm, result }) => | ||
` | ||
<details> | ||
<summary>${algorithm}</summary> | ||
## ${algorithm} | ||
\`\`\` | ||
${result} | ||
\`\`\` | ||
</details> | ||
` | ||
|
||
const pageMarkdownContent = `# Benchmarks | ||
Made with [mitata](https://github.com/evanwashere/mitata) library | ||
## Signing | ||
${signBenchmark.map(printDetail).join('\n')} | ||
## Decoding | ||
${decodeBenchmark.map(printDetail).join('\n')} | ||
Note that for decoding the algorithm is irrelevant, so only one was measured. | ||
## Verifying | ||
${verifyBenchmark.map(printDetail).join('\n')} | ||
` | ||
|
||
await writeFile(join(import.meta.dirname, 'README.md'), pageMarkdownContent, 'utf8') |
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 |
---|---|---|
@@ -1,21 +1,16 @@ | ||
'use strict' | ||
|
||
import { isMainThread } from 'worker_threads' | ||
import { tokens, publicKeys, compareVerifying, saveLogs } from './utils.mjs' | ||
|
||
async function runSuites() { | ||
if (!isMainThread) { | ||
const algorightm = process.env.CURRENT_ALGORITHM | ||
compareVerifying(tokens[algorightm], algorightm, publicKeys[algorightm]) | ||
return | ||
} else { | ||
for (const algorightm of ['HS512', 'ES512', 'RS512', 'PS512', 'EdDSA']) { | ||
process.env.CURRENT_ALGORITHM = algorightm | ||
await compareVerifying(tokens[algorightm], algorightm, publicKeys[algorightm]) | ||
} | ||
export async function runSuites() { | ||
const benchmarkResults = [] | ||
for (const algorithm of ['HS512', 'ES512', 'RS512', 'PS512', 'EdDSA']) { | ||
const result = await compareVerifying(tokens[algorithm], algorithm, publicKeys[algorithm]) | ||
benchmarkResults.push({ algorithm, result }) | ||
} | ||
|
||
await saveLogs('verify') | ||
return benchmarkResults | ||
} | ||
|
||
runSuites().catch(console.error) | ||
if (import.meta.filename === process.argv[1]) await runSuites() |
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