[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#12033: format should be faster
From: |
nalaginrut |
Subject: |
bug#12033: format should be faster |
Date: |
Mon, 20 Aug 2012 14:27:35 +0800 |
On Sun, 2012-08-19 at 00:19 +0200, Ludovic Courtès wrote:
> Hi!
>
> nalaginrut <address@hidden> skribis:
>
> > Our "format" is rather slow,
>
> What makes you say so?
>
> Did you make sure that the output port you’re writing to is buffered
> (this is not the case by default!)? See ‘setvbuf’.
>
OK, yes, I assumed the port will be buffered in default.
Should I set stdin/stdout(current-input-port/current-output-port) as
buffered each time?
But in my case, there's only current-output-port. And I set it as
buffered, the result is the same.
> > can we make it faster? I can only output strings with display if I
> > need an faster program, which is not so elegant.
>
> Until (ice-9 format) is loaded, ‘format’ is an alias for
> ‘simple-format’, which is implemented in C, less capable but faster than
> (ice-9 format). Perhaps that’s usable for your use case?
>
But I never use (ice-9 format).
There's ~15s difference between "display" and "format" in my laptop.
---------------code-1------------------
(define (main . args)
(let* ((ll ((@ (srfi srfi-1) iota) (read) 1)) (len (length ll)) (m (1-
(/ len 2))))
(display len)(newline)
(let lp((a (list-head ll (1+ m))) (b (list-tail ll (1+ m))) (n 1))
(and (< n len)
(for-each (lambda (x y) (display x)(display " ")(display y)(display "
")) a b)(newline)
(lp (append (list 1 (car b)) (cdr a)) (append (cdr b) (list (list-ref
a m))) (1+ n))))))
-----------------end-------------------
--------------code-2-------------------
(define (main . args)
(let* ((ll ((@ (srfi srfi-1) iota) (read) 1)) (len (length ll)) (m (1-
(/ len 2))))
(display len)(newline)
(let lp((a (list-head ll (1+ m))) (b (list-tail ll (1+ m))) (n 1))
(and (< n len)
(for-each (lambda (x y) (format #t "~a ~a~%" x y)) a b)
(lp (append (list 1 (car b)) (cdr a)) (append (cdr b) (list (list-ref
a m))) (1+ n))))))
---------------end---------------------
time { echo 6000 | ./test 1>/dev/null ;}
Code-1 is 0m30.326s
Code-2 is 0m45.310s
PS: Please use 6000 at least, or it's size is not representative.
> Thanks,
> Ludo’.
- bug#12033: format should be faster, Ludovic Courtès, 2012/08/18
- bug#12033: format should be faster,
nalaginrut <=
- bug#12033: format should be faster, Ludovic Courtès, 2012/08/20
- Message not available
- Message not available
- bug#12033: closed (Re: bug#12033: format should be faster), Ludovic Courtès, 2012/08/20
- bug#12033: closed (Re: bug#12033: format should be faster), nalaginrut, 2012/08/20
- bug#12033: closed (Re: bug#12033: format should be faster), Noah Lavine, 2012/08/20
- bug#12033: closed (Re: bug#12033: format should be faster), Ian Price, 2012/08/20
- bug#12033: closed (Re: bug#12033: format should be faster), Ludovic Courtès, 2012/08/21
- bug#12033: closed (Re: bug#12033: format should be faster), Noah Lavine, 2012/08/21
- bug#12033: closed (Re: bug#12033: format should be faster), Ludovic Courtès, 2012/08/21
- bug#12033: closed (Re: bug#12033: format should be faster), Andy Wingo, 2012/08/21
- bug#12033: closed (Re: bug#12033: format should be faster), nalaginrut, 2012/08/22