Timeline for How do I measure execution time of a command on the Windows command line?
Current License: CC BY-SA 4.0
28 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 3, 2024 at 17:04 | history | edited | Top-Master | CC BY-SA 4.0 |
formatting
|
| Oct 29, 2021 at 17:46 | comment | added | rint | Could you make the output format look like in Linux? For example: real 0m0.001s | |
| Dec 27, 2019 at 20:43 | review | Suggested edits | |||
| Dec 28, 2019 at 8:10 | |||||
| Jun 23, 2019 at 18:01 | comment | added | Paul |
For anyone wondering: the fixes by TomaszGandor and Jean-FrançoisLarvoire have been edited into the script above. Also @Jashan: there's a buggy bug in your milliseconds padding (it's actually hundredths, and you're using the secs var instead of ms), so it should be: set "ms=0%ms%" and set "ms=%ms:~-2%". But other than that, I like this!
|
|
| Feb 22, 2019 at 8:47 | comment | added | Jashan |
That's super useful. The only thing I felt I needed to add was zero-padding minutes, seconds and milliseconds, like so: :: Mission accomplished set /a totalsecs = %hours%*3600 + %mins%*60 + %secs% set "mins=0%mins%" set "mins=%mins:~-2%" set "secs=0%secs%" set "secs=%secs:~-2%" set "ms=00%ms%" set "ms=%secs:~-3%" echo Operation took %hours%:%mins%:%secs%.%ms% (%totalsecs%.%ms%s total)
|
|
| Jan 5, 2018 at 4:11 | review | Suggested edits | |||
| Jan 5, 2018 at 13:20 | |||||
| Nov 9, 2017 at 3:40 | comment | added | jwdonahue | I have a more composable version of this script. Should I edit the answer or add another to the thread? | |
| Nov 8, 2017 at 22:54 | comment | added | jwdonahue |
Utilities like this one should never turn echo off. It does not compose well, particularly when one is diagnosing script failures. Better to use @ prefix everywhere and let developers pin-hole enable echo within the script when/where needed.
|
|
| Jul 15, 2017 at 17:28 | history | edited | Peter Mortensen | CC BY-SA 3.0 |
Active reading. Removed meta information (this belongs in comments).
|
| Jun 9, 2017 at 12:25 | comment | added | mugiseyebrows |
works even better with %COMSPEC% /c %* instead of cmd /c %* (9th line) (cmd (C:\windows\system32) may not be in %PATH%)
|
|
| Apr 6, 2017 at 20:24 | comment | added | Euri Pinhollow | Cool but does not expose process time in any way. | |
| Nov 9, 2016 at 7:28 | comment | added | Nasri Najib | Observation for others not to dismiss too quickly any output. For me, even with a warning output, i.e. 'cmd' is not recognised as an internal or external command... , there is a response back. For me, it measures pause as 0.01s total. | |
| S Aug 24, 2016 at 18:58 | history | suggested | EM0 | CC BY-SA 3.0 |
Applied the fixes posted in comments by Tomasz Gandor and Jean-François Larvoire (tested)
|
| Aug 24, 2016 at 16:49 | review | Suggested edits | |||
| S Aug 24, 2016 at 18:58 | |||||
| Jul 9, 2016 at 16:19 | comment | added | thdoan |
Cool script. Note that once you disable echoing (@echo off), you no longer need to prefix setlocal with @.
|
|
| Dec 1, 2015 at 19:02 | comment | added | Valentin Tihomirov |
It seem not be able to handle spaces between 'command' with arguments. I had to quote everything like timeit "scala -J-Xmx33m ProxyDemo 15 1 > console". Probably it is worth noticing.
|
|
| Dec 2, 2014 at 16:04 | comment | added | Jean-François Larvoire |
There's a serious arithmetic error in that script: Try it with: set start=10:10:10.10 set end=10:11:10.09 And it'll output: command took 0:1:-1.99 (59.99s total) You should reverse the order of the 4 lines that do "lss 0" comparisons, so that the carry progresses correctly from low to high sexagesimal digits. Then the output becomes: command took 0:0:59.99 (59.99s total)
|
|
| Sep 11, 2014 at 18:25 | comment | added | Camilo Martin | @TomaszGandor Ah, that was it, then! To be honest, it pisses me off how Windows even has output from core commands localized, and it frequently breaks naive batch files. | |
| Sep 11, 2014 at 11:19 | comment | added | Tomasz Gandor |
@CamiloMartin & others who had this (like me) - you may have a locale, which uses COMMA instead of DOT for decimal. So, in this scrpit, change delims=:. to delims=:.,, and then it should work "across the board".
|
|
| Sep 11, 2014 at 10:33 | comment | added | Tomasz Gandor |
Before I use it, I will rewrite it into a function like :print_time_since <start>, to use it multiple times in a script from inside of it. BTW, nice string splitting and use of cmd's FOR hacks taken to the extreme!
|
|
| Sep 25, 2013 at 16:00 | comment | added | Camilo Martin |
For some reason this only gives me output in whole seconds... which for me is useless. I mean that I run timecmd pause, and it always results in 1.00 sec, 2.00 sec, 4.00 sec... even 0.00 sec! Windows 7.
|
|
| Aug 21, 2013 at 19:37 | comment | added | Brian J | @JesseChisholm In Windows 8 (and I've read in Windows 7 as well) you don't need the call for .bat | |
| Mar 27, 2013 at 16:50 | comment | added | Jesse Chisholm | replacing cmd /c %* with %* works unless your command is another batch file. Then you'd have to do timecmd call other.bat | |
| Aug 8, 2012 at 14:57 | history | edited | Scott Stafford | CC BY-SA 3.0 |
took the liberty of throwing in a setlocal and a total seconds calc
|
| Aug 8, 2012 at 2:34 | history | edited | user87453 | CC BY-SA 3.0 |
Formatting
|
| Aug 8, 2012 at 2:27 | history | edited | user87453 | CC BY-SA 3.0 |
Incorporated suggestion from @ScottStafford
|
| Jun 2, 2011 at 1:13 | history | edited | user87453 | CC BY-SA 3.0 |
Made description more accurate
|
| Jun 2, 2011 at 1:08 | history | answered | user87453 | CC BY-SA 3.0 |