Skip to content

Instantly share code, notes, and snippets.

@mohamedmansour
Created June 6, 2020 10:31
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 mohamedmansour/2e48b0a229d91bcb72db7a29adc8288e to your computer and use it in GitHub Desktop.
Save mohamedmansour/2e48b0a229d91bcb72db7a29adc8288e to your computer and use it in GitHub Desktop.
Measure how long any command takes on Windows
# Copyright (c) 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
This script converts two %time% compatible strings passed to it into seconds,
subtracts them, and prints the difference. That's it. It's used by timeit.bat.
"""
from __future__ import print_function
import re
import sys
def ParseTime(time_string):
# Time looks like 15:19:30.32 or 15:19:30,32 depending on locale
# (and there might be other variants as well)
match = re.match("(.*):(.*):(.*)[\.,](.*)", time_string)
hours, minutes, seconds, fraction = map(int, match.groups())
return hours * 3600 + minutes * 60 + seconds + fraction * .01
print("%1.2f seconds elapsed time" %
(ParseTime(sys.argv[1]) - ParseTime(sys.argv[2])))
@ECHO off
REM Copyright (c) 2017 The Chromium Authors. All rights reserved.
REM Use of this source code is governed by a BSD-style license that can be
REM found in the LICENSE file.
REM This batch file executes the commands passed to it and prints out the
REM elapsed run time.
SETLOCAL
SET starttime=%time%
CALL %*
CALL python %~dp0subtract_time.py %time% %starttime%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment