[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [MIT-Scheme-devel] string-head!
From: |
Taylor R Campbell |
Subject: |
Re: [MIT-Scheme-devel] string-head! |
Date: |
Thu, 24 Sep 2009 18:40:34 -0400 |
User-agent: |
IMAIL/1.21; Edwin/3.116; MIT-Scheme/7.7.90.+ |
Date: Thu, 24 Sep 2009 13:48:34 -0700
From: Joe Marshall <address@hidden>
Has anyone measured the performance difference between smashing
the string head and just taking a substring? I'd bet it's a pretty minimal
improvement against the background of the other things that happen during
I/O.
I conducted a thoroughly unscientific comparison whose source code is
attached: making a string of length 2^(i + 1), taking a prefix of
length 2^i, and then discarding it, repeating the process ten thousand
times. Using SUBSTRING becomes slower than SET-STRING-MAXIMUM-LENGTH!
when i is about 5. This is in line with SUBSTRING-MOVE-{LEFT,RIGHT}!,
actually, which defer to the primitive as soon as the string's length
exceeds 2^5. Winning on just GC time starts to happen when i is about
10. (Your mileage may vary, of course. I ran this code compiled, by
the way.)
So how about the following definition?
(define (string-head! string end)
(guarantee-string string 'STRING-HEAD!)
(guarantee-substring-end-index end (string-length string) 'STRING-HEAD!)
(if (and (fix:< end (string-length string))
(or (fix:< end 32) ;32 computed by science (ha!).
(begin
;; Some implementations of the microcode don't
;; support SET-STRING-MAXIMUM-LENGTH!. In this case,
;; defer to %STRING-HEAD.
((ucode-primitive set-string-maximum-length! 2) string end)
(not (fix:= end (string-maximum-length string))))))
(%string-head string end)
string))
test.scm
Description: Text Data
- [MIT-Scheme-devel] string-head!, Taylor R Campbell, 2009/09/24
- Re: [MIT-Scheme-devel] string-head!, Joe Marshall, 2009/09/24
- Re: [MIT-Scheme-devel] string-head!, Chris Hanson, 2009/09/24
- Re: [MIT-Scheme-devel] string-head!, Taylor R Campbell, 2009/09/24
- Re: [MIT-Scheme-devel] string-head!, Chris Hanson, 2009/09/24
- Re: [MIT-Scheme-devel] string-head!, Joe Marshall, 2009/09/24
- Re: [MIT-Scheme-devel] string-head!, Chris Hanson, 2009/09/24
- Re: [MIT-Scheme-devel] string-head!,
Taylor R Campbell <=
- Re: [MIT-Scheme-devel] string-head!, Joe Marshall, 2009/09/24