![]() ![]() Note, this Interface only works on Chrome 20 and 24+, Firefox 15+ and IE 10. ![]() I used the Performance Interface to get high precision, sub-millisecond numbers needed for this test. It’s not an Array, per se, but it works with the static access pattern that I need. ![]() Create an Object and access it’s key/value pairs directly using an Object pattern such as parsedImage.image1 or parseImage. This pattern should be the most familiar to everyone. Loop thru every element until I find the matching item, then break out of the loop. If this doesn’t make sense take a look at code in my JSFiddle. Then search for indexArray.indexOf(“some unique id”) and apply that integer against the primary Array, for example primaryArray to get your result. It only contains names or unique ids in the same exact order as the primary. Create an index Array based exactly on the primary Array. This is an array that once it is written you aren’t going to add anything new too it, you simply access its data as needed and when you are done you delete it. I looked at five ways to parse what I’ll call a static Array. The tests were completed using a pure JavaScript methodology, and no third party libraries were used, so that I could see exactly what was going on in the code. My objective was to coax out every last micro-ounce of performance. So I did some testing to decide on an approach with the best search times. I’ve been doing some performance tweaking on a very CPU intensive JavaScript application and I needed really fast in-memory searching on a temporary array before writing that data to IndexedDB. With a little bit of testing and tinkering, I found some methodologies were faster than others by close to 200%! There are many different ways to find an item in a JavaScript array.
0 Comments
Leave a Reply. |