Javascript Array lookup efficiency: associative vs. stored associative?

后端 未结 4 394
逝去的感伤
逝去的感伤 2021-02-04 19:52

I\'ve been reading, and they\'re saying that associative arrays won\'t give you the same efficiency as arrays. An associative array can look things up in O(N) time, where an ar

4条回答
  •  长情又很酷
    2021-02-04 20:37

    I posit that the present responses do not fully consider more practical use cases. I created this jsperf to demonstrate. While @Felix's jsperf demonstrates lookup speed, it's not performed on sufficiently large objects to be really useful. I think 10,000 simple properties is more reasonable. Further, you need to randomly select keys in the sequence to read, modify, delete and create to truly demonstrate the performance differences between the two types.

提交回复
热议问题