Reading arrays, 3 methods tested, results

Richard Gaskin ambassador at fourthworld.com
Wed Jul 27 15:48:39 EDT 2016


Thanks, Mark.  You know I loves me some benchmarking. :)

Do all three produce the same result?

- rg


Mark Talluto wrote:
 > Thought this might be interesting to those benchmarking reads on
 > arrays. I was working to optimize one small section of code in
 > our database and found that the method I figured would be the slowest
 > ended up being the fastest. Maybe this will be helpful to others
 > doing a lot of array work.
 >
 > Macbook Pro, macOS 10.11.5
 > LiveCode 8.1 dp2
 > Data: 135k records
 >
 >  (method 1) 1.36 seconds
 > --GET ALL THE RECORDS FROM THIS TABLE
 > repeat for each element xRecordClusterA in gCSIdatabaseA[xTableID]
 > 	repeat for each element xElement in xRecordClusterA
 > 		put xElement into tRecordA[xTableID][(the keys of xRecordClusterA)]
 > 	end repeat
 > end repeat
 >
 >
 > (method 2) 220 ms
 > --GET ALL THE RECORDS FROM THIS TABLE
 > repeat for each element xRecord in gCSIdatabaseA[xTableID]
 > 	repeat for each key xRecordID in xRecord
 > 		put xRecord [xRecordID] into tRecordA[xTableID][xRecordID]
 > 	end repeat
 > end repeat
 >
 >
 >  (method 3) 77 ms
 > --GET ALL THE RECORDS FROM THIS TABLE
 > repeat for each key xRecordCluster in gCSIdatabaseA[xTableID]
 > 	put the keys of gCSIdatabaseA[xTableID][xRecordCluster] into tRecordID
 > 	put gCSIdatabaseA[xTableID][xRecordCluster][tRecordID] into 
tRecordA[xTableID][tRecordID]
 > end repeat
 >





More information about the use-livecode mailing list