time_it.py 514 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/python
  2. import sys
  3. import time
  4. import subprocess
  5. import json
  6. def usage(f, st):
  7. f.write("Usage:\n")
  8. f.write(" time_it.py file utility [argument ...]\n\n")
  9. f.write("Writes running time of utility into file.\n")
  10. return st
  11. def main(argv):
  12. if 3 > len(argv):
  13. return usage(sys.stderr, -1)
  14. t = time.time()
  15. ret = subprocess.call(argv[2:])
  16. t = time.time() - t
  17. if 0 == ret:
  18. with open(argv[1], "w") as f:
  19. json.dump({"dt":t}, f)
  20. return ret
  21. if __name__ == "__main__":
  22. sys.exit(main(sys.argv))