为什么新的磁盘阵列慢? [英] why is new Array slow?

查看:168
本文介绍了为什么新的磁盘阵列慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比较操作时

var fat_cats = cats.slice()

var fat_cats = new Array(cats.length)

的性能差异是令人困惑的。

the performance differences are confusing.

在Firefox和Chrome 新阵列较慢(当它应该是更快,它只是分配一个空数组并没有这样做迭代结束吧)

In firefox and chrome new Array is slower (when it should be faster, it's just allocating an empty array and not doing iteration over it)

凡在IE8 新阵列快(这只是混淆)

Where as in IE8 new Array is faster (which is just confusing)

任何解释AP preciated。

Any explanation appreciated.

基准

推荐答案

想通了通过查看<一个href=\"http://$c$c.google.com/searchframe#W9JxUuHYyMg/trunk/src/array.js&q=slice%20package%3ahttp://v8%5C.google$c$c%5C.com&ct=rc&cd=9&sq=\"相对=nofollow>为V8的阵列功能源$ C ​​$ C 。

如果一个数组有超过1000个元素和 .slice 被称为 SmartSlice 用来调用的函数,经文以其它方式使用的 SimpleSlice 功能。

If an array has more than 1000 elements and .slice is called, a function called SmartSlice is used, verses the SimpleSlice function used otherwise.

SimpleSlice 被实现为一个循环副本(完全一样数组复制测试用例code)。 SmartSlice ,在另一方面,采用稀疏数组重新present的数据。

SimpleSlice is implemented as a for loop copy (exactly the same as the code in the array copy test case). SmartSlice, on the other hand, uses sparse arrays to represent the data.

测试用例的各种元素的数量为10,000降到1000以下,他们是完全相同的性能(误差范围之内),而在用更少的变化和更好的控制测试用例的超过1000元,则SmartSlice方法比幼稚副本快〜36%。

In a test case where the number of elements is dropped from 10,000 to below 1000, they are exactly the same performance (within the margin of error), whereas in a better-controlled test case with fewer variation and more than 1000 elements, the SmartSlice method is ~36% faster than the naïve copy.

虽然这完全说明了事情的V8一面,我不知道为什么火狐也慢于新阵列比切片阵列,即使在较小的尺寸 - 除非他们已经制定了类似的优化(也许是所有切片功能)。

While this explains the V8 side of things perfectly, I do not know why Firefox is also slower on new arrays than sliced arrays, even at smaller sizes - unless they have a similar optimization in place (perhaps for all slice functions).

修改

这不停地缠着我,于是我下载了Firefox的源和签出 JS / src目录/ jsarray.cpp array_slice ,和Firefox也有一个类似的优化:结果的 .slice DenseCopiedArray DenseAllocatedArray ,这是显然类似V8稀疏数组。

This kept bugging me, so I downloaded the Firefox source and checked out js/src/jsarray.cpp!array_slice, and Firefox does have a similar optimization: the result of .slice is a DenseCopiedArray or DenseAllocatedArray, which is apparently similar to the V8 sparse array.

这篇关于为什么新的磁盘阵列慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆