Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import operator
- import time
- KB = 1024
- MB = KB**2
- GB = MB*KB
- INT_SIZE = 4;
- ARRAY_MIN = KB
- ARRAY_MAX = (KB*4)**2
- x = [0]*ARRAY_MAX
- def step_range(start, end, step, step_func, compare_func):
- while compare_func(start, end):
- yield start
- start = step_func(start, step)
- def getSeconds():
- return time.time()
- def label(i):
- if i < 1e3:
- print '%1dB,'%(i),
- elif i < 1e6:
- print '%1dK,'%(i / KB),
- elif i < 1e9:
- print '%1dM,'%(i / MB),
- else:
- print '%1dG,'%(i / GB),
- def main():
- print ' ,',
- for stride in step_range(1, ARRAY_MAX / 2, 2, operator.mul, operator.le):
- label(int(stride*INT_SIZE))
- print
- # Main loop for each configuration
- for csize in step_range(ARRAY_MIN, ARRAY_MAX, 2, operator.mul, operator.le):
- label(int(csize * INT_SIZE)) #Print cache size for this loop
- for stride in step_range(1, csize / 2, 2, operator.mul, operator.le):
- # Layout path of memory references in array
- for index in step_range(0, csize, stride, operator.add, operator.lt):
- x[index] = index + stride
- x[index - stride] = 0
- ###print '[Stride='+str(stride)+']'
- ###print '',
- # Wait for timer to roll over
- lastsec = getSeconds()
- while True:
- sec0 = getSeconds()
- if long(sec0) != long(lastsec):
- break
- # Walk through path in array for twenty seconds
- # This gives 5% accuracy with second resolution
- steps = 0.0; # Number of steps taken
- nextstep = 0; # Start at beginning of path
- sec0 = getSeconds() # Start timer
- while True: # Repeat for 20 seconds
- for i in step_range(stride, 0, 1, operator.sub, operator.ne): # Keep sample size
- nextstep = 0
- while True:
- nextstep = x[nextstep]
- if nextstep == 0:
- break
- steps += 1
- sec1 = getSeconds()
- if (sec1 - sec0) >= 20.0:
- break
- sec = sec1 - sec0;
- # Repeat empty loop to loop subtracted overhead
- tsteps = 0.0; # used to match no. while iterations
- sec0 = getSeconds() # Start timer
- while True:
- for i in step_range(stride, 0, 1, operator.sub, operator.ne): # Keep sample size
- index = 0;
- while True:
- index += stride
- if index >= csize:
- break
- tsteps += 1
- sec1 = getSeconds()
- if tsteps >= steps:
- break
- sec -= (sec1 - sec0)
- loadtime = (sec * 1e9) / (steps * csize)
- # Write out results in CSV format
- val = 0.1 if loadtime < 0.1 else loadtime
- print '%4.1f,'%(val),
- print
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement