Skip to content

Instantly share code, notes, and snippets.

@IanConnolly
Created March 11, 2014 17:11
Show Gist options
  • Save IanConnolly/9490385 to your computer and use it in GitHub Desktop.
Save IanConnolly/9490385 to your computer and use it in GitHub Desktop.
hacky timer for CS3014 Parallel Matmul
import subprocess
import argparse
import sys
from random import randrange
BIG = 1000
SMALL = 100
def generate_data(big=False):
max_size = SMALL
if big:
max_size = BIG
a = randrange(max_size)
b = randrange(max_size)
c = randrange(max_size)
return [a, b, b, c]
def main():
parser = argparse.ArgumentParser(description="Timer for Parallel Matmul")
parser.add_argument("--big", action="store_true",\
help='run BIG tests (size upto 1000)')
args = parser.parse_args()
times = []
n_times = 10000
if args.big:
n_times = 10
for i in xrange(n_times):
data = " ".join(map(str, generate_data(args.big)))
p = subprocess.Popen('bin/matmul-harness {}'.format(data),\
shell=True, stdout=subprocess.PIPE,\
stderr=subprocess.STDOUT)
try:
output = p.stdout.readlines()[0]
except IndexError:
print "Error occurred for params: {}".format(data)
sys.exit(1)
print "Params: {}, {}".format(data, output.rstrip())
# hacky
time = int(output.split(" ")[2])
times.append(time)
average = reduce(lambda x, y: x + y, times) / float(len(times))
print "Ran {} times, average: {} microseconds".format(n_times, average)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment