Skip to content

Instantly share code, notes, and snippets.

@rpivo
Last active December 2, 2020 01:38
Show Gist options
  • Save rpivo/f02bbb8265f6d6bf9451298a72c605a0 to your computer and use it in GitHub Desktop.
Save rpivo/f02bbb8265f6d6bf9451298a72c605a0 to your computer and use it in GitHub Desktop.
Measuring Performance of Decimal Truncation Methods

Measuring Performance of Decimal Truncation Methods

The following operations all result in 2:

// fast, and the least amount of characters
~~2.5

// fast
2.5 | 0

// a little slower, but still fast, and probably the most readable
Math.trunc(2.5)

// embarrassingly slow
parseInt(`${2.5}`, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment