Created
July 18, 2010 18:40
-
-
Save mape/480607 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var userIds = []; | |
| // Create dummy ids | |
| for (var i=0; i < 10000; i++) { | |
| userIds.push('id-'+new Date().getTime()+Math.random()*100000000000000000+''+(Math.random()*100000000000000000)+''+(Math.random()*100000000000000000)); | |
| }; | |
| // Populate array with ids and users attached | |
| var usersArr = [] | |
| for (var i=0,l=users.length; i < l; i++) { | |
| usersArr.push({ | |
| 'id': userIds[i] | |
| , 'name': 'mape-'+userIds[i] | |
| }); | |
| }; | |
| // Populate object with ids and users attached | |
| var usersObj = [] | |
| for (var i=0,l=users.length; i < l; i++) { | |
| usersObj[userIds[i]] = { | |
| 'name': 'mape-'+userIds[i] | |
| } | |
| }; | |
| // Generate an id to find | |
| var randomId = userIds[Math.floor(Math.random()*userIds.length)]; | |
| console.log('Find: '+randomId); | |
| console.time('Fetch in array') | |
| for (var i=0,l=users.length; i < l; i++) { | |
| if (usersArr[i].id === randomId) | |
| { | |
| console.dir(usersArr[i]); | |
| break; | |
| } | |
| }; | |
| console.timeEnd('Fetch in array') | |
| console.time('Fetch in object') | |
| console.dir(usersObj[randomId]); | |
| console.timeEnd('Fetch in object') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment