guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Extremly slow for format & string-join


From: Nala Ginrut
Subject: Re: Extremly slow for format & string-join
Date: Mon, 01 Apr 2013 13:13:20 +0800

On Mon, 2013-04-01 at 12:39 +0800, Daniel Hartwig wrote:
> 2013/4/1 Nala Ginrut <address@hidden>:
> > I've tried to implement a function to mimic string multiply like Python:
> > "asdf" * 10
> >
> > --------------code----------------
> > (define (str* str n)
> >   (format #f "~{~a~}" (make-list n str)))
> >
> > or
> >
> > (define (str* str n)
> >   (string-join (make-list n str) ""))
> > --------------end-----------------
> >
> >
> 
> Those are both very general mechanisms, it does not suprise me that
> they are less than efficient for very large N.   Although I can not
> comment whether this is a worthwhile issue to address, I offer this
> snippet as a hint of something perhaps better for your specific case:
> 
> (define (str* str n)
>   (call-with-output-string
>     (lambda (p)
>       (let lp ((n n))
>         (unless (zero? n)
>           (display str p)
>           (lp (1- n)))))))
> 

Thanks! Good performance for such a function. ;-)

> Out of curiousity, how does the performance figures you showed compare
> to the Python operator for similarly large values of N?

Python does this very quickly, but I think your hint is enough for that.
My ideas are too elegant-pursuing.

Anyway, string-join is so slowly beyond my expectation.

Regards.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]