I assume, in 90% of all cases, we are just working with text or numbers which are text but look like text.
I tried to make a test to compare small and increasingly larger arrays/lists
I am working with LiveCode latest version 9.0 (dp 6) on Windows 10, 64 bit.
Here is the testing script:
Code: Select all
global gTableArray, gListArray local sTestResult on mouseUp lock screen set cursor to busy testArrayVizList end mouseUp command testArrayVizList put empty into msg put empty into sTestResult set the itemdelimiter to tab put "50,500,5000,50000,500000,1000000,2000000" into tTestIterations put replaceText (tTestIterations , "," , tab ) into tTestIterations repeat with i = 1 to the number of items of tTestIterations put item i of tTestIterations into tIteration put tIteration &tab after sTestResult put buildArray ( tIteration ) &tab after sTestResult put buildList ( tIteration ) after sTestResult put cr after sTestResult end repeat delete last char of sTestResult put sTestResult into msg end testArrayVizList function buildList pIteration put the milliseconds into startSec put empty into gListArray put "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z" into tCol put the number of items of tCol*1 into tNum put 0+0 into i /* Init local variable i */ repeat pIteration add 1 to i put item random ( tNum ) of tCol into tChar put i &","& tChar &CR after gListArray end repeat delete last char of gListArray return ( the milliseconds - startSec ) / 1000 end buildList function buildArray pIteration put the milliseconds into startSec put empty into gTableArray put "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z" into tCol put the number of items of tCol*1 into tNum put 0+0 into i repeat pIteration add 1 to i put item random ( tNum ) of tCol into tChar put tChar into gTableArray [ i ] [ "col" ] end repeat return ( the milliseconds - startSec ) / 1000 end buildArray
Interesting enough, when smaller amounts of data are used, the list performs better than the array. With large amounts of data, the situation changes. In my case, 500,000 repeats are the border line. From there building a list takes more and more time, while the array starts to perform better.
Here are the results in seconds (in fractions of seconds as milliseconds)
There is a problem: Building lists or arrays with something like 3-5 million repeats in this specific test case, LiveCode becomes non-responsive. On Windows it will show a turning icon. I thought it would regain focus, having the application run for several hours. But then I had to force-quit it. I found this situation in many cases when large amounts of data are loaded to memory. Is this a bug? Or is this something one should know beforehand?
Livecode has a pretty heavy system load. It uses 500 MB of memory, compared to Microsoft Excel with 24 MB, and Google Chrome with 130 MB. I was also wondering about this.
Assumed that only text data is used (no images, no binary files to be stored), would simple lists not be better than using arrays? Or is this a matter of personal preference (style/choice) ?