Created
January 8, 2023 00:46
-
-
Save H4ad/0d4efdf2b1ccd2f944419671aabb9db2 to your computer and use it in GitHub Desktop.
NestJS UUID to UID
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
// to run this file, install: npm i --save benchmark uuid uid [email protected] | |
// and then just run with: npx ts-node ids-benchmark.ts | |
import * as Benchmark from 'benchmark'; | |
import { uid } from 'uid'; | |
import * as uuid from 'uuid'; | |
import * as nanoid from 'nanoid'; | |
const suite = new Benchmark.Suite(); | |
suite.add('uuid', function () { | |
const id = uuid.v4(); | |
}); | |
suite.add('nanoid', function () { | |
const id = nanoid.nanoid(); | |
}); | |
suite.add('uid', function () { | |
const id = uid(21); | |
}); | |
suite | |
// add listeners | |
.on('cycle', function (event) { | |
console.log(String(event.target)); | |
}) | |
.on('complete', function () { | |
console.log('Fastest is ' + this.filter('fastest').map('name')); | |
}) | |
.run({ | |
async: true, | |
}); |
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
// this file I use to get the profiler information | |
// to run this file, compile to JavaScript first, | |
// then you run: node --prof dist/perf-startup-10000.js | |
// this will generate a file called: isolate-0xnnnnnnnnnnnn-v8.log | |
// to be able to read the information inside this file, run: | |
// node --prof-process isolate-0xnnnnnnnnnnnn-v8.log > processed.txt | |
import { AppModule } from '../src/app.module'; | |
import { NestFactory } from '@nestjs/core'; | |
import * as microtime from 'microtime'; | |
async function main() { | |
const start = microtime.now(); | |
for (let i = 0; i < 1e4; i++) | |
await NestFactory.create(AppModule, { logger: false }); | |
const end = microtime.now(); | |
console.log(`Diff: ${end - start}`); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment