'write-buffer' speed increase

Started by HPW, October 06, 2004, 12:16:29 AM

Previous topic - Next topic

HPW

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!
Hans-Peter

Lutz

#1
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

eddier

#2
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

HPW

#3
I use:



(write-buffer str (string "<table>" "<tr>" "<td>" .... ))
Hans-Peter

Lutz

#4
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

HPW

#5
The whole seems to be a good addition for the 'Tips and Tricks' section!



New topic: Fast string manipulation
Hans-Peter