Last active
October 27, 2017 14:28
-
-
Save jiunbae/6a10aba614e996750bbc8e0d0d9d3c72 to your computer and use it in GitHub Desktop.
plot drawer for Project3@ITE4065
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
#!/bin/python | |
''' | |
File name: draw.py | |
Author: Bae Jiun, Maybe | |
Date created: 10/27/2017 | |
Requirements: | |
- matplotlib | |
''' | |
from subprocess import Popen, PIPE | |
from os import environ, name | |
import matplotlib | |
if not (name == 'nt' or 'DISPLAY' in environ): | |
matplotlib.use('Agg') | |
TARGET = "run" | |
RANGE = [1, 2, 4, 8, 16, 32] | |
print ("Execute target file:", TARGET) | |
print ("Execute range:", RANGE) | |
def execute(count): | |
def parse(out): | |
if ':' in out: return int(out.split(':')[1]) | |
return int(out) | |
process = Popen(["./" + TARGET, str(count)], stdout=PIPE, stderr=PIPE) | |
stdout, stderr = process.communicate() | |
if stderr: | |
raise Exception('Error while running {} {}'.format(TARGET, count), stderr) | |
return parse(stdout.decode("utf-8")) | |
import matplotlib.pyplot as plt | |
fig = plt.figure() | |
for x, y in zip(RANGE, map(execute, RANGE)): | |
print ("Result update count: {} in thread count: {}".format(y, x)) | |
plt.scatter(x, y, color='BLACK') | |
# change y range if you need | |
# plt.ylim((25,250)) | |
plt.xlabel("thread") | |
plt.ylabel("update") | |
plt.savefig('result.png') | |
if name == 'nt' or 'DISPLAY' in environ: | |
plt.show() | |
plt.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment