Math.pow比使用临时任务的乘法更昂贵吗?

Pau*_*ine 5 javascript exponent

将javascript库移植到Python时,我发现了以下代码:

return Math.atan2(
    Math.sqrt(
       (_ = cos?1 * sin??) * _ + (_ = cos?0 * sin?1 - sin?0 * cos?1 * cos??) * _
    ), 
    sin?0 * sin?1 + cos?0 * cos?1 * cos??
);
Run Code Online (Sandbox Code Playgroud)

我错了还是(_ = cos?1 * sin??) * _写得像Math.pow(cos?1 * sin??, 2)

我想作者试图避免使用Math.pow,与临时分配相比,这在javascript中是否昂贵?

[更新]

截至2016年底,Chrome 53.0(64位)看起来差异并不像以前那么大.

Bro*_*ier 9

我能想到的唯一原因是表现.首先让我们测试他们是否真的这样做,我们没有忽略一些东西.

var test = (test = 5 * 2) * test; // 100
Math.pow(5 * 2, 2); // 100
Run Code Online (Sandbox Code Playgroud)

正如预期的那样,事实也证明了这一点.现在让我们看看他们是否使用jsperf有不同的表现.在这里查看:http://jsperf.com/...num-self

Firefox 23的差异非常小,但对于Safari而言,差异要大得多.使用Math.pow似乎在那里更昂贵.