开发者

Speed of Javascript array sort dependent on object size?

开发者 https://www.devze.com 2022-12-10 05:28 出处:网络
Hey out there in Stackland. I\'m making a very javascript-heavy site, and at a certain point I have to take a whole bunch of objects in an array and then sort them by their distanc开发者_开发百科e fr

Hey out there in Stackland.

I'm making a very javascript-heavy site, and at a certain point I have to take a whole bunch of objects in an array and then sort them by their distanc开发者_开发百科e from a certain point. I don't know the nature of objects in JS, and was wondering if this array sort would take longer with larger objects, or if it is the equivalent of changing pointers to different objects, which would mean that the size of the objects would be trivial. Any help would be great!

Thanks!


Values in JavaScript are either value types (booleans, null, numbers, strings) or reference types (objects, functions). There aren't any values that would be effectively large (strings are pointers behind the scenes) so your array sort speed should be only dependent on the number of items, not the size of them. Also, the base Array.sort() is faster than the one that takes a function, but you're kind of stuck with the latter.

0

精彩评论

暂无评论...
验证码 换一张
取 消