Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36
Chrome 93
Mac OS X 10.15.7
Desktop
2 years ago
Test name Executions per second
Math.random().toString(36).slice(-5) 3315275.0 Ops/sec
(+new Date).toString(36).slice(-5) 1857315.0 Ops/sec
btoa(Math.random()).slice(0, 5) 1069847.0 Ops/sec
btoa(+new Date).slice(-7, -2) 2213181.0 Ops/sec
btoa(+new Date).substr(-7, 5) 2247551.0 Ops/sec
Script Preparation code:
Tests:
  • Math.random().toString(36).slice(-5)

  • (+new Date).toString(36).slice(-5)

  • btoa(Math.random()).slice(0, 5)

  • btoa(+new Date).slice(-7, -2)

  • btoa(+new Date).substr(-7, 5)