Created
April 19, 2021 11:19
-
-
Save bytemain/86c4cf3b02d4280aafad71e0f1b04376 to your computer and use it in GitHub Desktop.
benchmark example
This file contains hidden or 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
| const Benchmark = require('benchmark'); | |
| const { md5, blake3 } = require('hash-wasm'); | |
| const map = { | |
| 'hash-wasm-md5': md5, | |
| 'hash-wasm-blake3': blake3, | |
| }; | |
| const _1b = '0'; | |
| const _10b = '0'.repeat(10); | |
| const _1k = _1b.repeat(1024); | |
| const _10k = _1b.repeat(1024 * 10); | |
| const _500k = _1b.repeat(1024 * 500); | |
| const _1m = _1b.repeat(1024 * 1024 * 1); | |
| const _2m = _1b.repeat(1024 * 1024 * 2); | |
| const _10m = _1b.repeat(1024 * 1024 * 10); | |
| const sizeMap = { | |
| '1b': _1b, | |
| '10b': _10b, | |
| '1k': _1k, | |
| '10k': _10k, | |
| '500k': _500k, | |
| '1m': _1m, | |
| '2m': _2m, | |
| '10m': _10m, | |
| }; | |
| const libs = Object.entries(map); | |
| const sizes = Object.entries(sizeMap); | |
| const suite = new Benchmark.Suite(); | |
| libs.forEach(([name, lib]) => { | |
| sizes.forEach(([sizeName, content]) => { | |
| suite.add(`${name}#${sizeName}`, () => { | |
| lib(content); | |
| }); | |
| }); | |
| }); | |
| suite | |
| .on('cycle', function (event) { | |
| console.log(String(event.target)); | |
| }) | |
| .run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment