calibrate.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. fancy = {"read_root": "read root ID",
  14. "read_dict": "read dictionary",
  15. "read_dict_keys": "read dictionary keys",
  16. "read_value": "read node value",
  17. "read_dict_node": "read dictionary by node",
  18. "rule_generation": "rule generation",
  19. "read_dict_edge": "read dictionary edge",
  20. "create_node": "create node",
  21. "create_edge": "create edge",
  22. "create_nodevalue": "create value",
  23. "create_dict": "create dictionary",
  24. "delete_edge": "delete edge",
  25. "delete_node": "delete node",
  26. "purge": "garbage collect",
  27. "read_reverse_dict": "dictionary key lookup",
  28. "read_outgoing": "read outgoing edges",
  29. "read_incoming": "read incoming edges",
  30. "read_edge": "read edge",
  31. "read_dict_node_edge": "read dictionary edge by node",
  32. }
  33. s = 0.0
  34. with open("calibration/averages", 'w') as averages:
  35. with open("calibration/plot", 'w') as plot:
  36. for op in operations:
  37. avg = sum(operations[op]) / len(operations[op])
  38. op_max = avg * 3
  39. new_list = []
  40. with open("calibration/distribution_%s" % op, 'w') as f:
  41. for t in operations[op]:
  42. f.write("%.17f\n" % float(t))
  43. averages.write("%20s: %.17f\n" % (op, avg))
  44. plot.write("set terminal postscript enhanced colour portrait size 6,6\n")
  45. plot.write("set xtics rotate by -45\n")
  46. plot.write("n = 20\n")
  47. plot.write("max=%s\n" % op_max)
  48. plot.write("width=max/n\n")
  49. plot.write("set boxwidth width absolute\n")
  50. plot.write("set style fill solid 1.0 noborder\n")
  51. plot.write("rounded(x)=width*floor(x/width)+width/2\n")
  52. plot.write("set out 'calibration/plot_%s.eps'\n" % op)
  53. plot.write("set ylabel 'Frequency (time)'\n")
  54. plot.write("set xlabel 'Duration (s)'\n")
  55. plot.write("set title 'Operation %s'\n" % op.replace("_", "\\_"))
  56. plot.write("plot 'calibration/distribution_%s' u (rounded($1)):(1) smooth freq w boxes title ''\n" % op)
  57. #print("%s: %s x %s = %s" % (op, avg, len(operations[op]), avg * len(operations[op])))
  58. print("% -23s&% -23s& %.8f\\\\" % (fancy[op], "{:,}".format(len(operations[op])), avg))
  59. s += avg * len(operations[op])
  60. #print("TOTAL: " + str(s))