# [Arrays] Random Access Times ?

Ron de Bruijn rondebruijn@yahoo.com
Sun, 4 May 2003 07:07:16 -0700 (PDT)

I am still experimenting with array's and I now do it
in Hugs. I have created a little program that creates
an array with 100001 elements(see below). After each
operation I print the time   so I can calculate how
long it took to execute. As you can see, the times get
increasingly bigger. I also swapped the first
(0..10000)with the last action (90000..100000) and it
seems the relation is dependant of the height of the
index. This is strange, isn't it?

And although I know have used Hugs, I want to use
somekind of array that I can use in GHC, because I
have seen some benchmarks of optimized code of GHC and
I was quite impressed. Is there anyone else out there,
that already has written a program that deals with
large fast mutable arrays? I really want to use
Haskell for a realworld application, but what I don't
want is that I find out after the time that I am
halfway programming from somebody:"Why didn't you use
the x-array, because that's x-times as fast?"

To understand below code somemore: "schrijf" means
write.

P.S. An array that I could use in GHC and in Hugs
would be best, because I kind of like the more
friendly look of WinHugs.

Greets Ron

module Test where

import IOExts
import CPUTime
import Time

schrijf arr i = writeIOArray arr i 5

main = do arr<-newIOArray (0,100000) 5
putStr "Arr aangemaakt"
x<-getClockTime
putStr \$ show (x)
sequence(map(schrijf arr) [0..10000])
x<-getClockTime
putStr \$ show (x)
sequence(map(schrijf arr) [10000..20000])
x<-getClockTime
putStr \$ show (x)
sequence(map(schrijf arr) [20000..30000])
x<-getClockTime
putStr \$ show (x)
sequence(map(schrijf arr) [30000..40000])
x<-getClockTime
putStr \$ show (x)
sequence(map(schrijf arr) [40000..50000])
x<-getClockTime
putStr \$ show (x)
sequence(map(schrijf arr) [50000..60000])
x<-getClockTime
putStr \$ show (x)
sequence(map(schrijf arr) [60000..70000])
x<-getClockTime
putStr \$ show (x)
sequence(map(schrijf arr) [70000..80000])
x<-getClockTime
putStr \$ show (x)
sequence(map(schrijf arr) [80000..90000])
x<-getClockTime
putStr \$ show (x)
sequence(map(schrijf arr) [90000..100000])
x<-getClockTime
putStr \$ show (x)
putStr "Klaar"

Arr aangemaaktSun May  4 15:38:57 West-Europa
(zomertijd) 2003Sun May  4 15:38:58 West-Europa (zome
rtijd) 2003Sun May  4 15:38:59 West-Europa (zomertijd)
2003Sun May  4 15:39:02 West-Europa (zomerti
jd) 2003Sun May  4 15:39:05 West-Europa (zomertijd)
2003Sun May  4 15:39:10 West-Europa (zomertijd)
2003Sun May  4 15:39:16 West-Europa (zomertijd)
2003Sun May  4 15:39:23 West-Europa (zomertijd) 20
03Sun May  4 15:39:32 West-Europa (zomertijd) 2003Sun
May  4 15:39:42 West-Europa (zomertijd) 2003S
un May  4 15:39:55 West-Europa (zomertijd) 2003Klaar

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com