Fantastic!
newLISP v.8.2.1 Copyright (c) 2004 Lutz Mueller. All rights reserved.
> (set 'str "")
""
> (time(dotimes (x 10000) (set 'str (string str "hello"))))
30614
> (set 'str "")
""
> (time(dotimes (x 10000) (set 'str (append str "hello"))))
301
> (set 'str "")
""
> (time(dotimes (x 10000) (write-buffer str "hello")))
10
>
> (set 'str "")
""
> (time(dotimes (x 10000) (write-buffer str (string "hello"))))
60
> (set 'str "")
""
> (time(dotimes (x 10000) (write-buffer str (string "hello" "test1"))))
90
>
>
This code show some speed, but then I changed my demo app with tower of Hanoi, where I have a timer for newlisp-execution time
I get a speed improvment from ca.940ms to 15ms. That's from waiting a second to immediately. Whow!
Excellent for script-generating!
Before I would push all strings on a list than reverser and join, which was faster than append, but still kind of clumsy.
The new way with 'write-buffer', will come in handy in a lot of programming areas like report writing, script generation etc..
Lutz
ps: write-line will not have it
Oh but if I could append many strings with it.
I use the following a bunch
(append "<table>" "<tr>" "<td>" .... )
What if
(write-buffer str ""<table>" "<tr>" "<td>" .... )
Eddie
I use:
(write-buffer str (string "<table>" "<tr>" "<td>" .... ))
If all strings to be written are already available in a list then 'append', 'join' or 'string' is fine, but if not then 'write-buffer' with string device is better.
Also note that 'string' is much slower then 'append', because it also converts from non-string to string, while append assumes, that all args are strings.
Also when you use string on a known type, i.e.:
(string lastname "," age)
where you know that age will always be a number than it is 3 times faster to do:
(format "%s,%d" age)
Lutz
The whole seems to be a good addition for the 'Tips and Tricks' section!
New topic: Fast string manipulation