`Math.pow(a, 2)` vs `a ** 2` vs `a * a`

Benchmark publishedon

Description

Math.pow vs power vs multiplication

Setup

const max = 100_000;
const x = Array.from({length: max}, () => Math.random() * max);

Test Runner

Initializing...

Testing in
Test CaseOps/sec
Math.pow
x.forEach((value) => Math.pow(value, 2))
ready
**
x.forEach((value) => value ** 2)
ready
*
x.forEach((value) => value * value)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

Revision 1
publishedon