Skip to content

Instantly share code, notes, and snippets.

@jameshwc
Last active January 3, 2020 09:53
Show Gist options
  • Save jameshwc/2cca03155432f6ab427434bbcfaa2cbb to your computer and use it in GitHub Desktop.
Save jameshwc/2cca03155432f6ab427434bbcfaa2cbb to your computer and use it in GitHub Desktop.
SP HW4 helper
import matplotlib.pyplot as plt
import os
def read_thread_time():
with open('thread_time', 'r') as file:
s = file.read()
s = s.split(',')[:-1]
s = [round(float(i),3) for i in s]
return s
def read_instructions():
with open('instructions', 'r') as file:
s = file.read()
s = [int(i.replace(',', '')) for i in s.split()]
print(s)
return s
def draw(s, output):
thread = [i for i in range(1,101)]
plt.plot(thread,s,color = 'r', label="execute time")
plt.ylabel("Execution time")
plt.xlabel("# of threads")
plt.savefig(output)
plt.clf()
if __name__ == '__main__':
# os.system('./timer.sh > thread_time')
draw(read_thread_time(), 'thread_time.png')
draw(read_instructions(), 'instructions.png')
#!/bin/bash
str=""
for i in {1..100}
do
perf stat -e instructions:u -v ./hw4 X_train y_train X_test $i
done
# post-processing
# cat instruction_num | grep instructions:u | sed -n 'n;p' | cut -d' ' -f4 > instructions
#!/bin/bash
str=""
for i in {1..100}
do
command="time ./hw4 X_train y_train X_test $i"
data=`eval "$command" 2>&1`
Time=`echo $data | cut -d' ' -f5`
minutes=`echo $Time | cut -d'm' -f1`
seconds=`echo $Time | cut -d'm' -f2 | cut -d's' -f1`
m2s=`expr $minutes \* 60`
t=`echo "$m2s+$seconds" | bc`
str="$str$t,"
echo $i" "$t>&2
done
echo $str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment