Created
August 20, 2016 06:35
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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