UNPKG

1.31 kBPlain TextView Raw
1/* eslint-disable @typescript-eslint/no-var-requires */
2/* eslint-disable @typescript-eslint/camelcase */
3/* eslint-disable no-console */
4import benchmark from 'nodemark'
5import Hashids from '../lib/hashids'
6import requireFromWeb from 'require-from-web'
7
8type HashidsType = typeof import('../lib/hashids').default
9
10const 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
22async 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
37void run()