io
about
blog
community
docs
downloads

    2007 01 07         Vector

    When doing operations on lists of numbers, it may be worth using the Vector primitive. A quick comparison:

    Vector
    
    Date secondsToRun(
        a := List clone
        100000 repeat(a append(Random value))
        a mapInPlace(squared) sum sqrt
    ) println
    
    Date secondsToRun(
        Vector clone setSize(100000) random(0, 1) square sum sqrt
    ) println
    
    Run results (on a 2Ghz Core Duo MacBookPro):
    0.615662
    0.003387
    
    The vectorized version is about than 200 times faster. This is also faster than it would be in C/C++ as Vector makes use of SIMD on OSX.