Sorry to disappoint Rob,

Make your script actually do some work and it runs a lot slower. I added the following two handlers to my menu button and the results were:

23 seconds to init the array and 20 sec to process (on a 1.8GHz G5). I have to add the array initialization time to your example because the arrays in my example are initially read from a .csv disk file, and must be converted into a keyed array first. I don't think you can beat the repeat for each, but I would certainly like to see it if you could.

Dennis

on init5
  put empty into gTestArrayX2
  put empty into gTestArrayY2
  repeat with i = 1 to 1000
    repeat with j = 1 to 1000
      put j into gTestArrayX2[i,j]
      put j into gTestArrayY2[i,j]
    end repeat
  end repeat
  put "Init5:"
end init5

on Method5 -- Add lines using keyed arrays
  put 0 into total
  repeat with i = 1 to 1000
    repeat with j = 1 to 1000
      add gTestArrayX2[i,j]+gTestArrayY2[i,j] to total
    end repeat
  end repeat
  put total&&"Keyed (Method5): "
end Method5


On Apr 27, 2005, at 10:46 AM, Rob Cozens wrote:

on mouseUp
  global gTestArrayX,gTestArrayY
  if gTestArray is empty then
    repeat with i = 1 to 1000
      repeat with j = 1 to 1000
        put j into gTestArrayX[x,y]
      end repeat
    end repeat
    put gTestArrayX into gTestArrayY
  end if
  put the long seconds into startTime
  Method5
  get the long seconds
  answer "Elapsed time ="&&(it-startTime)&&"seconds."
end mouseUp

on Method5 -- Add lines using keyed arrays
  global gTestArrayX,gTestArrayY
  put 0 into theTotal
  repeat with i = 1 to 1000
    repeat with j = 1 to 1000
      add gTestArrayX[x,y]to theTotal
      add gTestArrayY[x,y]to theTotal
    end repeat
  end repeat
  put theTotal&&"Keyed Method"
end Method5
_______________________________________________
use-revolution mailing list
[email protected]
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to