Created
March 11, 2014 17:11
-
-
Save IanConnolly/9490385 to your computer and use it in GitHub Desktop.
hacky timer for CS3014 Parallel Matmul
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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