Reversing a list
BNig
niggemann at uni-wh.de
Fri Apr 4 19:54:28 EDT 2008
hi Mark
if you fill up a field with like a button script like this:
on mouseUp pMouseBtnNo
put "A,B,C,D" into trandomChar
set the numberformat to "#####"
put 0 into tCounter
repeat 99999
add 1 to tCounter
put any item of trandomChar && tCounter & " a longer text to see
the difference between short and longn text on the time it takes to reverse
the order of a field" & return after tCollector
end repeat
delete last char of tCollector
put tCollector into field 1
end mouseUp
it creates a line of text in my view representative of an average line of
text:
"D 00001 a longer text to see the difference between short and longn text on
the time it takes to reverse the order of a field"
and if you compare
arrays
like
(Mark Schonewille)
--
on mouseUp pMouseBtnNo
put the millisec into tStart
put field 1 into temp
put reverseList(temp) into temp2
put temp2 into field 1
put the millisec - tStart
end mouseUp
private function reverseList theListArray
split theListArray by cr
combine theListArray by cr and tab
sort lines of theListArray numeric descending by item 1 of each
split theListArray by column
return theListArray[2]
end reverseList
--
it takes for 100.000 time 1800 millisecs on a macBook Pro 2.33
for an adapted Jaques/Jan solution (same field with 100.000 lines, same
computer):
---
local tCount
on mouseUp
put the millisec into tStart
put the number of lines of field 1 into tCount
sort field 1 numeric by mySort()
put the millisec - tStart
end mouseUp
private function mySort
subtract 1 from tCount
return tCount
end mySort
---
it takes about 850 millisecs
1800 millisecs versus 850 is a huge amount of time for the user (a lot of
gulps, by the way: what is the standard gulp anyway?, I know how to
transform the Percentage of the maximum velocity of sheep in a vacuum:
http://www.theregister.co.uk/Design/page/reg-standards-converter.html#velocity
, but you would have to submit the gulb as a distinct and defined unit of
time :-))))
Allright, I added "private" to the function which is only availabel to rev
=> 2.8.1.
it saves about 50 milliseconds.
So the solution proposed by Jaque and Jan is definitely faster and, provided
you add numeric, just as correct.
regards
Bernd
Richmond Mathewson wrote:
>
> Sarah Reichelt wrote:
>
> "And the winner is......."
>
> and jolly well done to Jacque!
>
> HOWEVER, what naive types like me would like to know
> are:
>
> 1. How did you time these routines ?
>
> For the sake of argument, I hardly had time to take a
> gulp of coffee before mine was done: presumably you
> don't do timings in gulps, semi-gulps, demi-semi-gulps
> and so on.
>
> 2. Although it is very clever (I, for one, had a bit
> of fun having a try) to write a routine that reverses
> a list a few demi-semi-gulps faster than another,
> until we are all using super computers to find out the
> question for 42 (pace Douglas Adams) I wonder why
> those few micro-gulps really might matter ?
>
> sincerely, Richmond Mathewson
>
> ____________________________________________________________
>
> A Thorn in the flesh is better than a failed Systems Development Life
> Cycle.
> ____________________________________________________________
>
>
> __________________________________________________________
> Sent from Yahoo! Mail.
> A Smarter Inbox http://uk.docs.yahoo.com/nowyoucan.html
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>
--
View this message in context: http://www.nabble.com/Reversing-a-list-tp16494644p16505535.html
Sent from the Revolution - User mailing list archive at Nabble.com.
More information about the use-livecode
mailing list