Have a look at the loops...!
[1/2] from: rebolinth:nodep:dds:nl at: 10-Apr-2002 23:17
OOo yes..well... I probably misinterpreted some functions :-)
But my goal was to check loops for speed...
There are 2 surpricingly strange outcomes below...
have a look...your input!/output! is welcome..
*********************************************************************
Timers on simple functions
no complex element structures.
Output to sdtout
Tested on a 486 66 Mhz 32 Mb
running core: 2.5.0.9.1
n: 100000
doloop: func [ n [integer!] ] [
start: now/time/precise
loop n [ prin "." ]
end: now/time/precise
print [ total: end - start ]
]
* Time loop: 0:01:33.52935
doforeach: func [ n [ integer!] ] [
dots: array/initial n "."
start: now/time/precise
foreach dot dots [ prin dots ]
end: now/time/precise
print [ total: end - start ]
]
* Time foreach: over 60 minutes !!!!!!!!!
(wont even finish untill now :)
(Also: The above func eats OS resources like a milky bar!!!..dammmmm...)
doforall: func [ n [integer!] ] [
dots: array/initial n "."
start: now/time/precise
forall dots [ prin first dots ]
end: now/time/precise
print [ total: end - start ]
]
* Time forall: 0:04:43.023292
doforskip: func [ n [integer!] ] [
dots: array/initial n "."
start: now/time/precise
forskip dots 1 [ prin first dots ]
end: now/time/precise
print [ total: end - start ]
]
* Time forskip: 0:04:13.541465
dowhile: func [ n [integer!] ] [
x: 0
start: now/time/precise
while [ x <= n ] [ [ prin "." ] x: x + 1 ]
end: now/time/precise
print [ total: end - start ]
]
* Time while: 0:00:04.03787
dosort1: func [ n [integer!] ] [
dots: array/initial n "."
start: now/time/precise
sort [ prin first dots ]
end: now/time/precise
print [ total: end - start ]
]
* Time sort1: 0:00:01.417908
dosort2: func [ n [integer!] ] [
dots: array/initial n (to-char random(256))
start: now/time/precise
sort [ prin first dots ]
end: now/time/precise
print [ total: end - start ]
]
* Time sort2: 0:00:00.978082
(Why is this quicker then sort1 ????, dont be fooled by random!!!)
dorepeat: func [ n [integer!] ] [
start: now/time/precise
repeat cnt n [ prin "." ]
end: now/time/precise
print [ total: end - start ]
]
* Time repeat: 0:01:44.671599
And finaly..
print now/time/precise array/initial 100000 "." print now/time/precise
* Time Array/initial: 0:00:00.317948
(R),
Norman.
[2/2] from: anton::lexicon::net at: 12-Apr-2002 0:52
> dosort1: func [ n [integer!] ] [
> dots: array/initial n "."
<<quoted lines omitted: 5>>
> * Time sort2: 0:00:00.978082
> (Why is this quicker then sort1 ????, dont be fooled by random!!!)
It's not random that's the issue.
In dosort1, you are adding n series to the array = a series of series.
In dosort2, you are adding n char!s to the array = a series of char!s.
char!s are a simpler datatype than a series, so it
makes sense to me that it's faster.
Anton.
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted