random-int.bench.ts 368 B

12345678910111213141516
  1. import { bench, group, run } from 'mitata';
  2. import { randomInt as nativeRandomInt } from 'crypto';
  3. const randomInt = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min;
  4. group('random-int', () => {
  5. bench('crypto.randomInt', () => {
  6. nativeRandomInt(3, 7);
  7. });
  8. bench('Math.random', () => {
  9. randomInt(3, 7);
  10. });
  11. });
  12. run();