[REBOL] Re: SHEEP vs Rebol (Pythagoras Tree)
From: philb:upnaway at: 15-Oct-2001 8:23
H Gregg/Allen,
Wow that really surprised me ....
Not Pre-allocated
15-Oct-2001/8:16:35.54+8:00
15-Oct-2001/8:16:41.03+8:00
05.49 seconds
Preallocated
15-Oct-2001/8:17:32.6+8:00
15-Oct-2001/8:17:33.1+8:00
0.5 seconds
That a 10 times improvement ....
This is on Windoze 98SE with 128 Mb of ram.
Cheers Phil
-- original message
Hi Gregg,
I think the modified script below will improve the first time performance by
quite a bit
for you. Pre allocating the space needed makes a big diff. (1/3 the time on
my machine)
Cheers,
Allen K
REBOL [
Comment: {
Converted to REBOL by Gregg Irwin for testing purposes.
Some speed mods. Pre-allocated block size, REBOLised the maths Allen K
}
]
pyth-tree: func [
a[pair!] b[pair!]
depth[integer!] face
/local c d e color
][
c: d: e: 0x0
color: depth * -10 + 0.255.0
c/x: a/x - a/y + b/y
c/y: a/x + a/y - b/x
d/x: b/x + b/y - a/y
d/y: a/x - b/x + b/y
e/x: c/x - c/y + d/x + d/y * 0.5
e/y: c/x + c/y - d/x + d/y * 0.5
append draw-cmds compose [pen (color) line (c) (a) (b) (d) (c) (e) (d)]
;append draw-cmds reduce [c a b d c e d]
;print [c a b d c e d]
;show face
if depth < 12 [
pyth-tree c e depth + 1 face
pyth-tree e d depth + 1 face
]
;wait .05
]
world-size: 640x520
start-pt-1: 266x450
start-pt-2: 374x450
lay: layout [
size world-size
backdrop black
origin 0x0
canvas: image 640x480
across
button "go" [
clear draw-cmds
;show canvas
print now/precise
pyth-tree start-pt-1 start-pt-2 0 canvas
print now/precise
;print length? draw-cmds
show canvas
]
button "quit" [quit]
]
; preallocate the space needed
canvas/effect: reduce ['draw draw-cmds: make block! 90000]
print ""
view lay