Re: Extremly slow for format & string-join

2013-04-02 Thread Ludovic Courtès
Mark H Weaver skribis: > Indeed, the implementation of 'string-join' was very bad: about O(n^2) [...] > Before: > > scheme@(guile-user)> ,time (define s (string-join (make-list 1 "test") > "-")) > ;; 0.998800s real time, 0.996677s run time. 0.984885s spent in GC. > scheme@(guile-user)> ,t

Re: Extremly slow for format & string-join

2013-04-01 Thread Ian Price
Nala Ginrut writes: > string-join is a common thing for text processing(include web develop). > However, our powerful 'format' is not so efficient. I do think it's > necessary to we spend some time on it. As Mark says, format is a not very nice piece of code to read, or to modify, so if you want

Re: Extremly slow for format & string-join

2013-04-01 Thread Thien-Thi Nguyen
() Nala Ginrut () Mon, 01 Apr 2013 12:00:01 +0800 (define (str* str n) (format #f "~{~a~}" (make-list n str))) (define (str* str n) (string-join (make-list n str) "")) Here's another implementation, using SRFI 13 ‘xsubstring’: (define (str* str n) (xsubstring str 0 (* n (stri

Re: Extremly slow for format & string-join

2013-04-01 Thread Nala Ginrut
On Mon, 2013-04-01 at 04:36 -0400, Mark H Weaver wrote: > Nala Ginrut writes: > > > 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

Re: Extremly slow for format & string-join

2013-04-01 Thread Mark H Weaver
Nala Ginrut writes: > 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) "")) >

Re: Extremly slow for format & string-join

2013-04-01 Thread Daniel Hartwig
On 1 April 2013 14:59, Daniel Llorens wrote: > > Hello, > >> From: Daniel Hartwig >> >> (define (str* str n) >> (call-with-output-string >>(lambda (p) >> (let lp ((n n)) >>(unless (zero? n) >> (display str p) >> (lp (1- n))) >> >> Out of curiousity, how doe

Re: Extremly slow for format & string-join

2013-04-01 Thread Daniel Hartwig
On 1 April 2013 14:58, Nala Ginrut wrote: > On Mon, 2013-04-01 at 13:35 +0800, Daniel Hartwig wrote: >> 2013/4/1 Nala Ginrut : >> > Anyway, string-join is so slowly beyond my expectation. >> >> Also note that ‘string-concatenate’ (less general than ‘string-join’) >> performs better for the same ca

Re: Extremly slow for format & string-join

2013-04-01 Thread Daniel Llorens
Hello, > From: Daniel Hartwig > > 2013/4/1 Nala Ginrut : >> 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)

Re: Extremly slow for format & string-join

2013-03-31 Thread Nala Ginrut
On Mon, 2013-04-01 at 13:35 +0800, Daniel Hartwig wrote: > 2013/4/1 Nala Ginrut : > > Anyway, string-join is so slowly beyond my expectation. > > Also note that ‘string-concatenate’ (less general than ‘string-join’) > performs better for the same case, you could use that directly instead > of my p

Re: Extremly slow for format & string-join

2013-03-31 Thread Daniel Hartwig
2013/4/1 Nala Ginrut : > Anyway, string-join is so slowly beyond my expectation. Also note that ‘string-concatenate’ (less general than ‘string-join’) performs better for the same case, you could use that directly instead of my prior suggestion for similar results. Especially since you do not des

Re: Extremly slow for format & string-join

2013-03-31 Thread Nala Ginrut
On Mon, 2013-04-01 at 12:39 +0800, Daniel Hartwig wrote: > 2013/4/1 Nala Ginrut : > > 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

Re: Extremly slow for format & string-join

2013-03-31 Thread Daniel Hartwig
2013/4/1 Nala Ginrut : > 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) "")) > ---