Script Preparation code:
Tests:

Historical Performance Data aggregated from 42 community runs

Desktop Results:
Chrome 18 runs
Classic int
2.9M/s
java nextInt16(bound)
2.9M/s
java nextInt32(bound)
2.8M/s
Classic 16
2.8M/s
Imul shf 16
2.8M/s
Mul shf 16
2.8M/s
Mul shf bigint
2.1M/s
Mul shf 32
1.2M/s

Fastest: Classic int (2.4x faster)

View exact numbers
  • Classic int: 2,909,317 ops/sec
  • java nextInt16(bound): 2,854,368 ops/sec
  • java nextInt32(bound): 2,796,083 ops/sec
  • Classic 16: 2,788,343 ops/sec
  • Imul shf 16: 2,787,498 ops/sec
  • Mul shf 16: 2,764,021 ops/sec
  • Mul shf bigint: 2,106,800 ops/sec
  • Mul shf 32: 1,228,541 ops/sec
Firefox 7 runs
java nextInt16(bound)
2.0M/s
Classic 16
1.9M/s
Mul shf 16
1.7M/s
Imul shf 16
1.7M/s
java nextInt32(bound)
1.7M/s
Mul shf bigint
1.3M/s
Mul shf 32
686K/s

Fastest: java nextInt16(bound) (2.9x faster)

View exact numbers
  • java nextInt16(bound): 1,987,199 ops/sec
  • Classic 16: 1,864,387 ops/sec
  • Mul shf 16: 1,715,306 ops/sec
  • Imul shf 16: 1,702,288 ops/sec
  • java nextInt32(bound): 1,652,137 ops/sec
  • Mul shf bigint: 1,311,774 ops/sec
  • Mul shf 32: 685,927 ops/sec
Mobile Results:
Chrome 17 runs
Classic 16
301K/s
Mul shf 16
269K/s
Classic 32
269K/s
Imul shf 16
268K/s
Mul shf bigint
220K/s
rejection sampling of modulo bias
174K/s
Debiased Integer Multiplication
173K/s
Bitmask with Rejection
156K/s
Mul shf 32
116K/s

Fastest: Classic 16 (2.6x faster)

View exact numbers
  • Classic 16: 300,936 ops/sec
  • Mul shf 16: 269,359 ops/sec
  • Classic 32: 269,209 ops/sec
  • Imul shf 16: 267,977 ops/sec
  • Mul shf bigint: 220,488 ops/sec
  • rejection sampling of modulo bias: 174,292 ops/sec
  • Debiased Integer Multiplication: 173,293 ops/sec
  • Bitmask with Rejection: 156,425 ops/sec
  • Mul shf 32: 115,938 ops/sec

Results show median performance across all community submissions. Run this benchmark yourself to verify on your device.

Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results
  • Test case name Result
    Classic 16
    Mul shf 16
    Imul shf 16
    Classic int
    Mul shf bigint
    Mul shf 32
    java nextInt16(bound)
    java nextInt32(bound)

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Chrome 137 on Windows
View result in a separate tab
Classic 16
3.2M/s
Mul shf 16
3.2M/s
Imul shf 16
3.1M/s
Classic int
3.1M/s
java nextInt32(bound)
3.1M/s
java nextInt16(bound)
3.0M/s
Mul shf bigint
2.4M/s
Mul shf 32
1.4M/s
View exact numbers
Test name Executions per second
Classic 16 3,156,994 Ops/sec
Mul shf 16 3,150,880 Ops/sec
Imul shf 16 3,149,801 Ops/sec
Classic int 3,133,590 Ops/sec
java nextInt32(bound) 3,113,806 Ops/sec
java nextInt16(bound) 2,981,598 Ops/sec
Mul shf bigint 2,397,238 Ops/sec
Mul shf 32 1,395,642 Ops/sec