calibrate.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import sys
  2. operations = {}
  3. with open(sys.argv[1] if len(sys.argv) > 1 else "calibration/result", 'r') as f:
  4. for l in f:
  5. try:
  6. op, t = l.split(": ")
  7. if "LOG" in op:
  8. continue
  9. t = float(t)
  10. operations.setdefault(op, []).append(t)
  11. except:
  12. pass
  13. s = 0.0
  14. with open("calibration/averages", 'w') as averages:
  15. with open("calibration/plot", 'w') as plot:
  16. for op in operations:
  17. avg = sum(operations[op]) / len(operations[op])
  18. op_max = avg * 3
  19. new_list = []
  20. with open("calibration/distribution_%s" % op, 'w') as f:
  21. for t in operations[op]:
  22. f.write("%.17f\n" % float(t))
  23. averages.write("%20s: %.17f\n" % (op, avg))
  24. plot.write("set terminal postscript enhanced colour portrait size 6,6\n")
  25. plot.write("set xtics rotate by -45\n")
  26. plot.write("n = 20\n")
  27. plot.write("max=%s\n" % op_max)
  28. plot.write("width=max/n\n")
  29. plot.write("set boxwidth width absolute\n")
  30. plot.write("set style fill solid 1.0 noborder\n")
  31. plot.write("rounded(x)=width*floor(x/width)+width/2\n")
  32. plot.write("set out 'calibration/plot_%s.eps'\n" % op)
  33. plot.write("set ylabel 'Frequency (time)'\n")
  34. plot.write("set xlabel 'Duration (s)'\n")
  35. plot.write("set title 'Operation %s'\n" % op.replace("_", "\\_"))
  36. plot.write("plot 'calibration/distribution_%s' u (rounded($1)):(1) smooth freq w boxes title ''\n" % op)
  37. print("%s: %s x %s = %s" % (op, avg, len(operations[op]), avg * len(operations[op])))
  38. s += avg * len(operations[op])
  39. print("TOTAL: " + str(s))