Min function

-hh hh at livecode.org
Sun Feb 28 09:58:18 EST 2016


Hi Thierry,

I have to correct my remark:
At first, case 2 will loose some merits, because after the first replace
linesOfNumbers is already a comma separated list and remains that.

We should write it like that?
-- case 2
  repeat nRepeat
    put LinesOfNumbers into nn
    replace return with comma in nn
    put min(nn)  into min2
  end repeat

I also found, that sorting is best in LC 7/8:
-- case 4
  repeat nRepeat
    put LinesOfNumbers into nn
    sort nn numeric
    put line 1 of nn into min4
  end repeat

The results here (what a difference between versions ...)

version: replaceText - replace - min() - sort

6.7.9: Done in 0.32 - 0.07 - 0.06 - 0.18
7.1.2: Done in 1.97 - 4.83 - 1.55 - 0.95 
8.0.0: Done in 2.09 - 4.89 - 2.89 - 1.00

Tested with (your slightly modified script):

on mouseUp
  repeat with i=1 to 1000
    get random( 1000)
    put IT & cr after LinesOfNumbers
    put IT & comma after OneLineOfNumbers
    put IT into b[i]
  end repeat
  delete last char of LinesOfNumbers
  delete last char of OneLineOfNumbers
  put 100 into nRepeat
  put the milliseconds into _ct
  -- case 1
  repeat nRepeat
    put min( replaceText( LinesOfNumbers, return,comma))  into min1
  end repeat
  put (the milliseconds - _ct)  / nRepeat into timing1
  wait 1 ticks with messages
  put the milliseconds into _ct
  -- case 2
  repeat nRepeat
    put LinesOfNumbers into nn
    replace return with comma in nn
    put min(nn) into min2
  end repeat
  put (the milliseconds - _ct)  / nRepeat into timing2
  wait 1 ticks with messages
  put the milliseconds into _ct
  -- case 3
  repeat nRepeat
    put min( OneLineOfNumbers) into min3
  end repeat
  put (the milliseconds - _ct)  / nRepeat into timing3
  wait 1 ticks with messages
  put the milliseconds into _ct
  -- case 4
  repeat nRepeat
    put LinesOfNumbers into nn
    sort nn numeric
    put line 1 of nn into min4
  end repeat
  put (the milliseconds - _ct)  / nRepeat into timing4
  put format( "Done in %.2f - %.2f -  %.2f -  %.2f %s %s %s %s", \
        timing1,  timing2, timing3, timing4, min1 is min3, min2 is min3, min4 is min3) into fld 1
end mouseUp






More information about the Use-livecode mailing list