'write-buffer' speed increase

For the Compleat Fan
Locked
HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

'write-buffer' speed increase

Post by HPW »

Fantastic!

Code: Select all

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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Post by eddier »

Oh but if I could append many strings with it.

I use the following a bunch

Code: Select all

(append "<table>" "<tr>" "<td>" .... )
What if

Code: Select all

(write-buffer str ""<table>" "<tr>" "<td>" .... )
Eddie

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

I use:

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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

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

New topic: Fast string manipulation
Hans-Peter

Locked