slow mutable-array-data

Berthold Bäuml <[email protected]>
Newsgroups gmane.comp.lang.racket.user,gmane.lisp.scheme.plt
Message-ID <[email protected]>
Converting a mutable-array into a vector in Racket (not Typed Racket) seems to be faster when done element-wise  instead of using mutable-array-data. Why is this? I always thought crossing the untyped/typed boundary as little as possible makes things run faster.

This little test program 

#lang racket
(require math/array)

(define arr (mutable-array #[#[1. 2. 3.] #[4. 5. 6.]]))

(define (array->vector1 arr)
  (for/vector [(a (in-array arr))] a))

(define (array->vector2 arr)
  (mutable-array-data arr))

(define N 5000)
(time (for [(i N)] (array->vector1 arr)))
(time (for [(i N)] (array->vector2 arr)))


results in

racket arr-vec.rkt   
cpu time: 946 real time: 961 gc time: 58
cpu time: 1270 real time: 1283 gc time: 4

Best,
Berthold

-- 
-----------------------------------------------------------------------
Berthold Bäuml -- Head of Autonomous Learning Robots Lab
DLR, Robotics and Mechatronics Center (RMC)
Münchner Str. 20, D-82234 Wessling
Phone +49 8153 282489
http://www.robotic.de/Berthold.Baeuml

-- 
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.