Skip to content

Instantly share code, notes, and snippets.

@dgrant
Created August 20, 2016 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgrant/e118eb83cc98d6a397e76d83e13af411 to your computer and use it in GitHub Desktop.
Save dgrant/e118eb83cc98d6a397e76d83e13af411 to your computer and use it in GitHub Desktop.
A script that measure how long execution of something took, good for Windows where there is no "time" command
#!/usr/bin/env python
import subprocess
import sys
import time
def main():
start_time = time.time()
subprocess.call(' '.join(sys.argv[1:]), shell=True)
delta = time.time() - start_time
hours = int(round(delta / 3600, 0))
minutes = int(round((delta % 3600) / 60, 0))
seconds = round((delta % 3600) % 60, 3)
hours_str = "{0}h ".format(hours) if hours != 0 else ''
minutes_str = "{0}m ".format(minutes) if (minutes != 0 or hours_str != '') else ''
seconds_str = "{0}s".format(seconds)
sys.stderr.write("Took: {0}{1}{2}\n".format(hours_str, minutes_str, seconds_str))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment