[REBOL] Re: New competition: do you accept the challenge?! :-)
From: tomc:cs:uoregon at: 6-Nov-2007 14:30
Sunanda wrote:
> Two very quick changes just to get into the spirit of the competition:
> 1. pre-allocate all space needed to the strings
> 2. use insert tail rather than append (append is not native in R2)
>
> Runs in about 65% of the time of the original. Still not as close
> as Java, but it was only a minute's work.
>
> Someone is sure to do much better.
>
> I suspect both Java and REBOL depend on the string handling
> libraries of the compiler they are compiled under. That may mean
> the relative timings will vary according to platform and release.
>
> Sunanda
>
> Changed code.....
> print "START..."
> s1: now
> str: make string! 5000
> finale: make string! 50000
> repeat i 10000 [
> clear str
> repeat j 500 [
> insert tail str reduce [i "," j "-"]
> ]
> insert tail finale copy/part skip str 1 4
> ]
> print "STOP!"
> print length? finale
> print (now/time - s1/time)
>
what Sun said with a little cheating
rebol []
print "START..."
s1: now
str: make string! 4800
finale: make string! 48000
repeat i 10000 [
repeat j 500[
insert tail str i
;insert tail str ","
insert tail str j
;insert tail str "-"
]
insert tail finale copy/part str 2
insert back tail finale ","
insert tail finale "-"
clear str
]
print "STOP!"
print length? finale
print (now/time - s1/time)
halt
--
... nice weather eh tomc-cs.uoregon.edu