From: Evan M. <eva...@gm...> - 2007-06-02 08:00:07
|
Hi, I am doing a numerical simulation in common lisp (SBCL), and I need to print a large amount of double-precision floating point numbers into an ASCII file. >From what I read, SBCL uses a state of the art for float printing, but I noticed that it is still quite slow, about 4 seconds to print 100,000 times the number pi, whereas Chicken scheme (which is quite fast but not the fastest implementation around) would take about 0.5 seconds with my small benchmark below. I thought initially that it was a type problem so I tryed to cal directly the underlying print function sb-impl::output-float, but the results are similar. Also, with both SBCL and Chicken I tried to change the output to /dev/null or to print not pi but random numbers generated in the loop, but the run times are roughly the same. Are there some options that I overlooked that could make the code run faster? Thanks in advance, Evan evan@evan:~$ sbcl This is SBCL 0.9.17, an implementation of ANSI Common Lisp. More information about SBCL is available at <http://www.sbcl.org/>. SBCL is free software, provided as is, with absolutely no warranty. It is mostly in the public domain; some portions are provided under BSD-style licenses. See the CREDITS and COPYING files in the distribution for more information. ; loading system definition from ; /usr/local/lib/sbcl/sb-bsd-sockets/sb-bsd-sockets.asd into #<PACKAGE "ASDF0"> ; registering #<SYSTEM SB-BSD-SOCKETS {B26BF89}> as SB-BSD-SOCKETS ; registering #<SYSTEM SB-BSD-SOCKETS-TESTS {A7BD271}> as SB-BSD-SOCKETS-TESTS ; loading system definition from /usr/local/lib/sbcl/sb-posix/sb-posix.asd into ; #<PACKAGE "ASDF0"> ; registering #<SYSTEM SB-POSIX {A9A58E9}> as SB-POSIX ; registering #<SYSTEM SB-POSIX-TESTS {AAC5031}> as SB-POSIX-TESTS * (defun float-sbcl-1 (&optional (n 100000)) (declare (optimize (speed 3) (safety 0)) (fixnum n)) (with-open-file (out "/tmp/float-sbcl1.dat" :direction :output :if-exists :supersede :if-does-not-exist :create) (let ((*print-pretty* nil)) (loop :repeat n :do (print pi out))))) FLOAT-SBCL-1 * (defun float-sbcl-2 (&optional (n 100000)) (declare (optimize (speed 3) (safety 0)) (fixnum n)) (with-open-file (out "/tmp/float-sbcl2.dat" :direction :output :if-exists :supersede :if-does-not-exist :create) (let ((*print-pretty* nil)) (loop :repeat n :do (progn (sb-impl::output-float pi out) (write-char #\newline out)))))) FLOAT-SBCL-2 * (time (float-sbcl-1)) Evaluation took: 4.467 seconds of real time 4.256266 seconds of user run time 0.048003 seconds of system run time [Run times include 0.132 seconds GC run time.] 0 calls to %EVAL 1 page fault and 281,611,432 bytes consed. NIL * (time (float-sbcl-2)) Evaluation took: 4.268 seconds of real time 4.192262 seconds of user run time 0.016001 seconds of system run time [Run times include 0.088 seconds GC run time.] 0 calls to %EVAL 0 page faults and 281,600,392 bytes consed. NIL * (quit) evan@evan:~$ cat print-float.scm (define *times* 100000) (define *pi* 3.141592653589793) (define *file* (open-output-file "/tmp/float-chicken.dat")) (let loop ((i 0)) (when (< i *times*) (display *pi* *file*) (newline *file*) (loop (+ i 1)))) (close-output-port *file*) evan@evan:~$ csc -V / / / ___ (___ ___ ( ___ ___ | | )| | |___)|___)| ) |__ | / | |__ | \ |__ | / Version 2.6 - linux-unix-gnu-x86 - [ dload ptables applyhook ] (c)2000-2007 Felix L. Winkelmann Enter "chicken -help" for information on how to use it. evan@YahooBB219198244001:~$ csc print-float.scm evan@YahooBB219198244001:~$ time ./print-float real 0m0.546s user 0m0.352s sys 0m0.020s evan@YahooBB219198244001:~$ |