function for greatest object in list less than or equal to a value

hh hh at
Tue Oct 13 09:42:55 EDT 2015

Similar things are useful for a very specialized statistical
evaluation I have to do soon, so I tested again with LC 7:

There is an interesting difference between LC versions 6 and 7.

The 'direct way' of GC reveals now as clearly fastest.

Tested with one of GC's 12 MB strings on a Mac mini(i5 2.5 GHz),
testString() as below, and a critical value of v=500000000.
The (correct) result is 499999246, used time is in seconds.

[a] LC 6.7.7
repeat-PMB	0.326  <- fastest
repeat-GC	0.350
repeat-hh	0.445
sort-GC		0.985

[b] LC 7.1.0
repeat-PMB	3.562
repeat-GC	1.483  <- fastest, the only one with a factor < 9
repeat-hh      1163.0 <- an ARRAY BUG? :-(
sort-GC   	8.156


function testString 
   set randomseed to 1444826515
   -- so you'll get exactly my test string
   repeat 1000000
      put comma & random(1000000000) after L
   end repeat
   delete byte 1 of L
   return L
end testString

function repeatPMB L,v  --[1]
  repeat for each item i in L
      if i < v then put comma & i after outL
   end repeat
   return max(outL)
end repeatPMB

function repeatGC L,v  --[2]
   put empty into R
   repeat for each item i in L
      if i < v and i > R then put i into R
   end repeat
   return R
end repeatGC

function repeathh L,v  --[3]
  repeat for each item i in L
      put comma & i after z[i < v]
   end repeat
   return max(z[true])
end repeathh

function sortGC L,v  --[4]
   sort items of L descending numeric
   sort items of L by (each >= v)
   return item 1 of L
end sortGC

More information about the use-livecode mailing list