var result = 0
var tmp = Math.pow(6, 21);
result ^= tmp;
var tmp = 6 ** 21;
result ^= tmp;
var tmp = 6 * 6 * 6 * 6 * 6 * 6 * 6 * 6 * 6 * 6 * 6 * 6 * 6 * 6 * 6 * 6 * 6 * 6 * 6 * 6 * 6;
result ^= tmp;
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
pow | |
** | |
* |
Test name | Executions per second |
---|---|
pow | 6819876.5 Ops/sec |
** | 12881229.0 Ops/sec |
* | 12853953.0 Ops/sec |
What is being tested?
The benchmark measures the performance of three different methods to calculate the power of a number:
Math.pow
(pow): The built-in JavaScript function that raises one number to another.Options compared
The benchmark compares the performance of these three methods on the same test case: calculating 6^21
. The results are measured in terms of Executions Per Second, which indicates how many times each method can execute within a second.
Pros and Cons of each approach:
Math.pow
, might not work in older JavaScript versions or environments.Math.pow
and the shorthand operator.Other considerations
Libraries used
None are explicitly mentioned in the provided code snippets.
Special JS features or syntax
The exponentiation shorthand operator ( **
) is a relatively recent addition to JavaScript (introduced in ECMAScript 2016), and it's not widely supported by older browsers or engines.