[racket-dev] for/vector much slower than vector-set! ?

From: John Clements (clements at brinckerhoff.org)
Date: Mon Jul 18 18:01:15 EDT 2011

I was testing the speed of vector creation, and I was surprised to see that for/vector seems much slower than using 'for' with an explicit vector-set!

(printf "let's try just generating a big vector.\n")
(rtavg (for/vector ([i (in-range (* 100 sr))]) 0.243))
(printf "\n\n")

(printf "how about with explicit vector-set! ?\n")
 (let ([v (make-vector (* 100 sr))])
   (for ([i (in-range (vector-length v))])
     (vector-set! v i 0.243))))
(printf "\n\n")


let's try just generating a big vector.
2.218 seconds

how about with explicit vector-set! ?
0.089 seconds

Does the first one somehow have to check some things that the second one doesn't?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4624 bytes
Desc: not available
URL: <http://lists.racket-lang.org/dev/archive/attachments/20110718/66149bfa/attachment.p7s>

Posted on the dev mailing list.