Script Preparation code:
AخA
 
var count = 1000;
Tests:
  • trunc

     
    for (var i = 0; i < count; i++) {
      Math.trunc(12.34 * 10);
      Math.trunc(567.89 * 10);
    }
  • round

     
    for (var i = 0; i < count; i++) {
      Math.round(12.34 * 10);
      Math.round(567.89 * 10);
    }
  • floor

     
    for (var i = 0; i < count; i++) {
      Math.floor(12.34 * 10);
      Math.floor(567.89 * 10);
    }
  • parseFloat to int

     
    for (var i = 0; i < count; i++) {
      parseFloat((12.34 * 10).toFixed());
      parseFloat((567.89 * 10).toFixed());
    }
  • ~~

     
    for (var i = 0; i < count; i++) {
      ~~(12.34 * 10);
      ~~(567.89 * 10);
    }
  • |0

     
    for (var i = 0; i < count; i++) {
      (12.34 * 10 |0);
      (567.89 * 10 |0);
    }
  • parseInt

     
    for (var i = 0; i < count; i++) {
      parseInt(12.34 * 10);
      parseInt(567.89 * 10);
    }
  • parseInt, 10

     
    for (var i = 0; i < count; i++) {
      parseInt(12.34 * 10, 10);
      parseInt(567.89 * 10, 10);
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    trunc
    round
    floor
    parseFloat to int
    ~~
    |0
    parseInt
    parseInt, 10

    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; rv:123.0) Gecko/20100101 Firefox/123.0
Firefox 123 on Windows
View result in a separate tab
Test name Executions per second
trunc 3857105.2 Ops/sec
round 3845987.2 Ops/sec
floor 3858572.5 Ops/sec
parseFloat to int 11734.7 Ops/sec
~~ 3888677.5 Ops/sec
|0 3912829.8 Ops/sec
parseInt 3732859.0 Ops/sec
parseInt, 10 3873018.2 Ops/sec