Hello,
I've been given a question to answer as part of my university course.
"Write a program that attempts to determine the size of a computers caches. It might not be very accurate, or
might be affected by other active processes running in parallel. It might also produce numerical output that
will require manual interpretion after being plotted."
I can choose either to write the program in Java or C. I don't know any C so I'll have to attempt this in Java. Saying that, I don't know how to do it in Java!
I have been given a tip:
One could run a program that randomly accesses a memory array of size 2 n words,
measuring the average access time.
Plotting this time should show a roughly constant access time whilst the majority of values
are accessed in the cache. When the cache size is exceeded, the hit rate will decrease
significantly, and this should be clearly visible on the graph.
I could do with more tips.. :)
- When I try to create a massive array (new int[Integer.MAX_VALUE];) I get a OutOfMemory exception..
- Am I meant to try and create an array that is larger than the cache, like keep creating arrays of size that doubles each time until the array is bigger than the cache?
- How do I measure the 'hit rate' of retrieving a value from the array? Is it as simple as
long delay = System.currentTimeMillis();
int test = array[array.length-1];
delay = System.currentTimeMillis() - delay;
Any help is massively appreciated
Edited by: jackCharlez on Dec 26, 2009 1:40 PM