calibrate.py 1.7 KB

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