Making Revolution faster with really big arrays
Wouter
wouter.abraham at scarlet.be
Fri Apr 29 06:24:53 EDT 2005
On 28 Apr 2005, at 17:59, Dennis Brown wrote:
> Frank,
>
> This is a simplified algorithm that I think would best translate
> directly between Transcript and PostgreSQL for a time trial. Just
> make sure the PostgreSQL code is an item by item algorithm also.
>
> Thanks,
> Dennis
>
> Transcript output on my machine: 1,000,000 Element Sum = 500500000
> Elapsed Time = 11.467659 seconds.
>
> on mouseUp
> global gTestArray
> if number of lines of the keys of gTestArray is not 1000000 then
> --already done the init
> put empty into gTestArray --start with an empty a variable
> repeat with x = 1 to 1000
> repeat with y = 1 to 1000
> put x into gTestArray[x,y]
> end repeat
> end repeat
> end if
> --
> put the long seconds into st
> Method6
> get the long seconds
> put " Elapsed Time ="&&(it - st)&&"seconds." after msg
> end mouseUp
>
> on Method6 -- Add elements using keyed arrays
> global gTestArray
> put 0 into total
> repeat with x = 1 to 1000
> repeat with y = 1 to 1000
> add gTestArray[x,y] to total
> end repeat
> end repeat
> put "1,000,000 Element Sum = "&total
> end Method6
> --
>
Hi again with a little addition,
The initialization of the test array takes about 36 seconds.
Following version does the same in much shorter time:
on mouseUp
put the long seconds into zap
--if number of lines of the keys of gTestArray is not 1000000 then
--already done the init
put empty into gTestArray --start with an empty a variable
repeat with i = 1 to 1000
put i&comma after x
end repeat
repeat 1000
put x after gTestArray
end repeat
split gTestArray by comma
put the long seconds - zap
--end if
put the long seconds into st
Method6
get the long seconds
put " Elapsed Time ="&&(it - st)&&"seconds." after msg
end mouseUp
In this case the initialization takes about 10 seconds on the slowbook
More information about the use-livecode
mailing list