-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.py
executable file
·59 lines (45 loc) · 1.23 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 8 10:48:23 2017
@author: mateo
"""
import subprocess
import fileinput
import sys
from matplotlib import pyplot as plt
BIN_NAME = "Release/CycleCounter_Windows.exe"
def __main__():
if sys.platform == "win32":
if len(sys.argv) >= 2:
iterations = int(sys.argv[1])
else:
iterations = 2000
output = get_stdout(iterations)
ints = to_ints(output)
else:
output = read_stdin()
ints = [int(line) for line in output]
plt.plot(ints)
plt.ylabel("CPU cycles per multiplication")
plt.xlabel("Iterations")
# plt.gca().set_ylim(bottom=0)
plt.show()
def to_ints(string):
"""
Converts a newline-separated string into a list of ints
"""
as_list = string.splitlines()
return [int(item) for item in as_list]
def get_stdout(iterations):
"""
Executes the cycle counter and returns the standard output.
"""
args = (BIN_NAME, str(iterations))
popen = subprocess.Popen(args, stdout=subprocess.PIPE)
popen.wait()
output = popen.stdout.read()
return output.decode("utf-8")
def read_stdin():
return [line for line in fileinput.input()]
__main__()