New topic: fastest method for Key paired values lookup
<http://forums.realsoftware.com/viewtopic.php?t=44042> Page 1 of 1 [ 8 posts ] Previous topic | Next topic Author Message Poco Post subject: fastest method for Key paired values lookupPosted: Thu May 17, 2012 3:50 am Joined: Sun Oct 04, 2009 1:05 pm Posts: 62 Location: FRANCE Hi All, In my app I receive data from USB. Every time a data is posted (I use a Timer.period = 100 for the moment), I need to read that value and correct it with an associated value in a table. For instance : I USB sends "1,000"; then I need to find in a "table/dictionary/...." the value "1,000" and correct it with the associated value in that table. This needs to be as fast as possible. What would you recomand? _________________ TIA, Configuration : MBA Mac OS Snow Real Studio 2010 r5 Top DaveS Post subject: Re: fastest method for Key paired values lookupPosted: Thu May 17, 2012 8:40 am Joined: Sun Aug 05, 2007 10:46 am Posts: 3700 Location: San Diego, CA If your entries are unique ... you only have ONE entry for "1,000" as the key then use a Dictionary look up HASKEY function _________________ Dave Sisemore MacPro, OSX 10.7.3 RB2011r3 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Top Poco Post subject: Re: fastest method for Key paired values lookupPosted: Thu May 17, 2012 8:48 am Joined: Sun Oct 04, 2009 1:05 pm Posts: 62 Location: FRANCE The first "row" is a list of 8,000 ordered integer. The second "row is Integer. Is my strategy ok for speed? - At startup read the text file containing the values and store it in a dictionay. Thus it will be stored in RAM (yes?) and the access will be quicker Thanks for your help. _________________ TIA, Configuration : MBA Mac OS Snow Real Studio 2010 r5 Top Jason_Adams Post subject: Re: fastest method for Key paired values lookupPosted: Thu May 17, 2012 9:25 am Joined: Fri Nov 10, 2006 4:10 pm Posts: 1570 Location: Michigan, USA It doesn't really matter what the key-value types are, so long as the keys remain unique. Yes, this keeps everything in memory (so be mindful of this), but that will yield the fastest solution. Hope this helps. _________________ Windows 7 Ultimate x64 Windows XP Pro SP3 Ubuntu 11.04 via Virtual Box RS Enterprise 2011r4 Programming Tutorials & Free Projects: http://www.JasonTheAdams.com "Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton Top Jym Post subject: Re: fastest method for Key paired values lookupPosted: Thu May 17, 2012 9:35 am Joined: Sat Oct 01, 2005 5:19 pm Posts: 3044 Really? A dictionary is faster than in-memory database? I find that hard to believe. I can get an array of classes to 'find' faster than dictionary (or at least it was that way in 2008 ish) Top Jason_Adams Post subject: Re: fastest method for Key paired values lookupPosted: Thu May 17, 2012 9:46 am Joined: Fri Nov 10, 2006 4:10 pm Posts: 1570 Location: Michigan, USA Jym wrote:Really? A dictionary is faster than in-memory database? I find that hard to believe. I can get an array of classes to 'find' faster than dictionary (or at least it was that way in 2008 ish) I honestly don't know. That'd be an interesting test. I suspect it depends on the size and complexity of what's being stored. The dictionary has the immediate advantage of not having to serialize/de-serialize class types. I believe what would eventually do in the Dictionary is how quickly it will consume memory in comparison to the database which will work with memory and disk. So, in true programmer fashion, my response will be: it depends. _________________ Windows 7 Ultimate x64 Windows XP Pro SP3 Ubuntu 11.04 via Virtual Box RS Enterprise 2011r4 Programming Tutorials & Free Projects: http://www.JasonTheAdams.com "Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton Top Poco Post subject: Re: fastest method for Key paired values lookupPosted: Thu May 17, 2012 10:48 am Joined: Sun Oct 04, 2009 1:05 pm Posts: 62 Location: FRANCE Jym wrote:Really? A dictionary is faster than in-memory database? I find that hard to believe. I can get an array of classes to 'find' faster than dictionary (or at least it was that way in 2008 ish) How do you program an in-memory database? DB are usually stored on files on disk? _________________ TIA, Configuration : MBA Mac OS Snow Real Studio 2010 r5 Top DaveS Post subject: Re: fastest method for Key paired values lookupPosted: Thu May 17, 2012 10:55 am Joined: Sun Aug 05, 2007 10:46 am Posts: 3700 Location: San Diego, CA For a list of 8,000 ordered pairs of integers... I would say a Dictionary would be much faster. and if that 8000 is actually 1 to 8000 then an ARRAY of 8000 items would be faster still.... but ONLY if the keys were consecutive and sequential. for that matter.... depending on the lowest/highest value.. a sparsely populated array might even be a possiblity. _________________ Dave Sisemore MacPro, OSX 10.7.3 RB2011r3 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 8 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
