1 |
|
2 |
|
3 |
|
4 | import benchmark from 'nodemark'
|
5 | import Hashids from '../lib/hashids'
|
6 | import requireFromWeb from 'require-from-web'
|
7 |
|
8 | type HashidsType = typeof import('../lib/hashids').default
|
9 |
|
10 | const benchmarkVersion = (Hashids: HashidsType, version: string) => {
|
11 | const hashids = new Hashids()
|
12 | const encoded = '5KoLLVL49RLhYkppOplM6piwWNNANny8N'
|
13 | const decoded = [9007199254740991, 9007199254740991, 9007199254740991]
|
14 |
|
15 | const decoding = benchmark(() => hashids.decode(encoded))
|
16 | const encoding = benchmark(() => hashids.encode(decoded))
|
17 |
|
18 | console.log(version, '\tdecoding\t', decoding)
|
19 | console.log(version, '\tencoding\t', encoding)
|
20 | }
|
21 |
|
22 | async function run() {
|
23 | const {default: Hashids_v1_2_2} = await requireFromWeb<{
|
24 | default: HashidsType
|
25 | }>('https://unpkg.com/hashids@1.2.2/dist/index.js')
|
26 | const {default: Hashids_v2_1_0} = await requireFromWeb<{
|
27 | default: HashidsType
|
28 | }>('https://unpkg.com/hashids@2.1.0/dist/hashids.js')
|
29 | const Hashids_transpiled = require('../cjs')
|
30 |
|
31 | benchmarkVersion(Hashids_v1_2_2, '1.2.2')
|
32 | benchmarkVersion(Hashids_v2_1_0, '2.1.0')
|
33 | benchmarkVersion(Hashids_transpiled, 'transpiled')
|
34 | benchmarkVersion(Hashids, 'node')
|
35 | }
|
36 |
|
37 | void run()
|