Nice shirleyquirk!

I guess I should just use arrays when performance really matters and I know the 
size compile time. Would you do it like this?
    
    
    import sequtils
    import random
    import times
    
    const
        size = 10_000_000
        iterations = 100_000_000
    
    type
        MyArray = array[size, int]
    
    proc main() =
        
        var xs: MyArray
        
        for i in 0..<size:
            xs[i] = rand(0..10)
        
        var start = cpuTime()
        for i in 0..<iterations:
            let x = xs.sample
        echo "time taken sample: ", cpuTime() - start
        
        start = cpuTime()
        for i in 0..<iterations:
            let x = xs[rand(size - 1)]
        echo "time taken rand: ", cpuTime() - start
    
    
    main()
    
    
    Run

Reply via email to