[Fluxus] vector operations performance
evan.raskob [lists]
lists at lowfrequency.org
Mon May 18 02:37:09 PDT 2009
Interesting results... For vaddx, garbage collection time just about
doubles when you add 3 random vectors, but vadd actually
*decreases*? That seems odd to me.
On May 18, 2009, at 4:10 AM, gabor papp wrote:
>>> As long as it doesn't impact performance, please feel free to
>>> improve
> i am testing the performance of vector operators and comparing them to
> simple macros that can handle every vector sizes. i attached a vadd
> test. it turns out that it is even a bit faster than the c++ version,
> probably due to the scheme->c conversion overhead.
>
> adding 2 random vectors:
> vadd: 0.00564 0.00783 0.0007
> vaddx: 0.00401 0.00724 0.00056
>
> adding 3 random vectors:
> vadd: 0.00608 0.01074 0.00064
> vaddx: 0.00489 0.00951 0.00108
>
> the results are calculated by adding the vectors 100000 times and
> calculating the average time needed to execute the instructions.
> vadd is
> the current vector addition fluxus uses, vaddx is the macro attached.
> the three numbers are: the number of milliseconds of CPU time required
> to obtain this result, the number of "real" milliseconds required for
> the result, and the number of milliseconds of CPU time spent on
> garbage
> collection.
>
> what do you think? can we change the vector operations to more
> flexible
> scheme versions or am i overlooking something?
>
> best,
> gabor
>
>
> ----------------------------
>
> (define (vadd2 a b)
> (build-vector (vector-length a)
> (lambda (i)
> (+ (vector-ref a i)
> (vector-ref b i)))))
>
> (define-syntax vaddx
> (syntax-rules ()
> [(vaddx a b) (vadd2 a b)]
> [(vaddx a b c ...) (vadd2 a (vaddx b c ...))]))
>
> (define (profile f n)
> (let ([timing-info
> (map (lambda (x)
> (exact->inexact (/ x n)))
> (foldl (lambda (vl al)
> (map + vl al))
> (list 0 0 0)
> (for/list ([i (in-range n)])
> (let-values ([(v cpu user gc) (time-apply f
> '())])
> (list cpu user gc)))))])
> (printf "~a ~a ~a~n" (list-ref timing-info 0)
> (list-ref timing-info 1)
> (list-ref timing-info 2))))
>
> (display "vadd: ")
> (profile (lambda () (vadd (rndvec) (rndvec))) 100000)
>
> (display "vaddx: ")
> (profile (lambda () (vaddx (rndvec) (rndvec))) 100000)
>
Evan Raskob
Top Floor
4-8 Arcola Street
London E8 2DJ
United Kingdom
More information about the Fluxus
mailing list