From: Sascha Wilde
Subject: optimizing formated output
Date: 
Message-ID: <3lkntfF13b5ncU1@individual.net>
Hello *,

I have written some very simple functions to manipulate and write
picture files in ppm format[0].

Now I have the problem, that writing out the ppm files takes _very_
long.[1]  It turns out, that writing big amounts of formated output
is the cause -- as a simplified example proofs:

CL-USER> (time (with-open-file (file "/tmp/test.txt"
				     :direction :output
				     :if-exists :supersede)
		 (let ((fmt (formatter "~a ~a ~a  ")))
		   (dotimes (i (* 640 480))
		   (format file fmt 1 2 3)))))
Evaluation took:
  21.657 seconds of real time
  14.632775 seconds of user run time
  4.510314 seconds of system run time
  0 page faults and
  1,599,841,408 bytes consed.
NIL

How can this be optimized?  

I'd expect writing a file like this not to taking longer than a few
seconds. (a unoptimized version of the same code in C takes not even a
second)

cheers
sascha

[0] <http://netpbm.sourceforge.net/doc/ppm.html>
[1] about 25 seconds for an 640x480 rgb ppm 
    on an 800 MHz Athlon Linux box, using sbcl.
-- 
Sascha Wilde 
- no sig today... sorry!

From: Edi Weitz
Subject: Re: optimizing formated output
Date: 
Message-ID: <u3bpmoif1.fsf@agharta.de>
On Sat, 06 Aug 2005 23:20:49 +0200, Sascha Wilde <······@sha-bang.de> wrote:

> I have written some very simple functions to manipulate and write
> picture files in ppm format[0].
>
> Now I have the problem, that writing out the ppm files takes _very_
> long.[1] It turns out, that writing big amounts of formated output
> is the cause -- as a simplified example proofs:
>
> CL-USER> (time (with-open-file (file "/tmp/test.txt"
> 				     :direction :output
> 				     :if-exists :supersede)
> 		 (let ((fmt (formatter "~a ~a ~a  ")))
> 		   (dotimes (i (* 640 480))
> 		   (format file fmt 1 2 3)))))
> Evaluation took:
>   21.657 seconds of real time
>   14.632775 seconds of user run time
>   4.510314 seconds of system run time
>   0 page faults and
>   1,599,841,408 bytes consed.
> NIL
>
> How can this be optimized?  

Try to bind *PRINT-PRETTY* to NIL and see if it makes a difference.

Cheers,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Sascha Wilde
Subject: Re: optimizing formated output
Date: 
Message-ID: <3lkqtqF133p9sU1@individual.net>
Edi Weitz <········@agharta.de> wrote:

> On Sat, 06 Aug 2005 23:20:49 +0200, Sascha Wilde <······@sha-bang.de> wrote:

>> Now I have the problem, that writing out the ppm files takes _very_
>> long.[1] It turns out, that writing big amounts of formated output
>> is the cause -- as a simplified example proofs:
>>
>> CL-USER> (time (with-open-file (file "/tmp/test.txt"
>> 				     :direction :output
>> 				     :if-exists :supersede)
>> 		 (let ((fmt (formatter "~a ~a ~a  ")))
>> 		   (dotimes (i (* 640 480))
>> 		   (format file fmt 1 2 3)))))
>> Evaluation took:
>>   21.657 seconds of real time
>>   14.632775 seconds of user run time
>>   4.510314 seconds of system run time
>>   0 page faults and
>>   1,599,841,408 bytes consed.
>> NIL
>>
>> How can this be optimized?  
>
> Try to bind *PRINT-PRETTY* to NIL and see if it makes a difference.

(time (with-open-file (file "/tmp/test.txt"
 				     :direction :output
 				     :if-exists :supersede)
 		 (let ((*print-pretty* nil)
		       (fmt (formatter "~a ~a ~a  ")))
 		   (dotimes (i (* 640 480))
 		   (format file fmt 1 2 3)))))
Evaluation took:
  2.455 seconds of real time
  2.263656 seconds of user run time
  0.12698 seconds of system run time
  0 page faults and
  7,381,832 bytes consed.

Yes, helps a lot!  Thanks for the hint.

cheers
sascha
-- 
Sascha Wilde
Wer HTML postet oder gepostetes HTML quotet oder sich gepostetes oder
gequotetes HTML beschafft, um es in Verkehr zu bringen, wird geplonkt.
From: Barry Margolin
Subject: Re: optimizing formated output
Date: 
Message-ID: <barmar-080D97.22452806082005@comcast.dca.giganews.com>
In article <···············@individual.net>,
 Sascha Wilde <······@sha-bang.de> wrote:

> Edi Weitz <········@agharta.de> wrote:
> 
> > On Sat, 06 Aug 2005 23:20:49 +0200, Sascha Wilde <······@sha-bang.de> wrote:
> 
> >> Now I have the problem, that writing out the ppm files takes _very_
> >> long.[1] It turns out, that writing big amounts of formated output
> >> is the cause -- as a simplified example proofs:
> >>
> >> CL-USER> (time (with-open-file (file "/tmp/test.txt"
> >> 				     :direction :output
> >> 				     :if-exists :supersede)
> >> 		 (let ((fmt (formatter "~a ~a ~a  ")))
> >> 		   (dotimes (i (* 640 480))
> >> 		   (format file fmt 1 2 3)))))
> >> Evaluation took:
> >>   21.657 seconds of real time
> >>   14.632775 seconds of user run time
> >>   4.510314 seconds of system run time
> >>   0 page faults and
> >>   1,599,841,408 bytes consed.
> >> NIL
> >>
> >> How can this be optimized?  
> >
> > Try to bind *PRINT-PRETTY* to NIL and see if it makes a difference.
> 
> (time (with-open-file (file "/tmp/test.txt"
>  				     :direction :output
>  				     :if-exists :supersede)
>  		 (let ((*print-pretty* nil)
> 		       (fmt (formatter "~a ~a ~a  ")))
>  		   (dotimes (i (* 640 480))
>  		   (format file fmt 1 2 3)))))
> Evaluation took:
>   2.455 seconds of real time
>   2.263656 seconds of user run time
>   0.12698 seconds of system run time
>   0 page faults and
>   7,381,832 bytes consed.
> 
> Yes, helps a lot!  Thanks for the hint.

Another thing that should help is compiling it.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Edi Weitz
Subject: Re: optimizing formated output
Date: 
Message-ID: <uu0i2nsw0.fsf@agharta.de>
On Sat, 06 Aug 2005 22:45:28 -0400, Barry Margolin <······@alum.mit.edu> wrote:

> Another thing that should help is compiling it.

Probably not in his case as he said that he was using SBCL.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")