{"id":10618,"date":"2019-08-05T16:06:34","date_gmt":"2019-08-05T10:36:34","guid":{"rendered":"http:\/\/198.58.113.91\/blog\/?p=10618"},"modified":"2023-08-05T23:08:38","modified_gmt":"2023-08-05T17:38:38","slug":"find-the-total-execution-time-of-command-program-windows","status":"publish","type":"post","link":"https:\/\/www.winhelponline.com\/blog\/find-the-total-execution-time-of-command-program-windows\/","title":{"rendered":"Find the Total Execution Time of a Command or Program in Windows"},"content":{"rendered":"<p>You may sometimes want to to find the total execution time of a command or program you run. To optimize a script or program, it&#8217;s essential to know how long does it take for it to complete execution. This helps you compare the total run time of Program A vs. Program B and optimize your code, especially if you&#8217;re a professional software developer, analyst, or software tester.<\/p>\n<p>Measuring the total execution time of a script or process is one of the most critical aspects of performance optimization. This article discusses various methods to find the total execution time of a program, script, or command in Windows.<\/p>\n<p><!--more--><\/p>\n<h2>Find the Total Execution Time of a Program or Command<\/h2>\n<h3>Using PowerShell<\/h3>\n<p>PowerShell includes the built-in <code>Measure-Command<\/code> cmdlet that helps you measure the time it takes to run script blocks, cmdlets, or even external programs. Here is a sample PowerShell command-line which measures the times takes for the <code>ping google.com<\/code> command-line to finish:<\/p>\n<pre>Measure-Command { ping google.com | Out-Host }<\/pre>\n<p>After the ping command&#8217;s output, you&#8217;ll see the following statistics at the bottom.<\/p>\n<pre>Days : 0\r\nHours : 0\r\nMinutes : 0\r\nSeconds : 3\r\nMilliseconds : 66\r\nTicks : 30660017\r\nTotalDays : 3.5486130787037E-05\r\nTotalHours : 0.000851667138888889\r\nTotalMinutes : 0.0511000283333333\r\nTotalSeconds : 3.0660017\r\nTotalMilliseconds : 3066.0017<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10620\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/08\/find-execution-time-measure-1.png\" alt=\"measure total execution time of a command or program\" width=\"699\" height=\"398\" \/><\/p>\n<p><em>Read more about <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/microsoft.powershell.utility\/measure-object?view=powershell-6\" target=\"_blank\" rel=\"noopener noreferrer\">Measure-Object<\/a> at Microsoft Docs.<\/em><\/p>\n<p>The command took 3.06 seconds to complete. The <code>Out-Host<\/code> argument, if omitted, PowerShell hides the output (of <code>Ping<\/code> command) in the console &#8212; you&#8217;ll see only the execution statistics.<\/p>\n<p>If you have a lengthy command-line or you need to run multiple commands, you can put them in a Windows batch file and then run it using PowerShell. Here is an example:<\/p>\n<pre>Measure-Command { Start-Process \"d:\\batch\\backup.bat\" | Out-Host }<\/pre>\n<div class=\"rp\"><strong>RELATED:<\/strong> <a href=\"https:\/\/www.winhelponline.com\/blog\/find-amount-words-lines-chars-text-file-powershell\/\">Find the Amount of Words, Chars and Lines in a Text File Using PowerShell<\/a><\/div>\n<hr \/>\n<h3>Using VBScript<\/h3>\n<p>Here is a simple VBScript that calculates the total execution time of a command-line, program, or batch file.<\/p>\n<pre>Set WshShell = WScript.CreateObject(\"WScript.Shell\")\r\nsCmd = chr(34) &amp; \"D:\\Batch Files\\Backup.bat\" &amp; chr(34)\r\ndtmStartTime = Timer\r\nReturn = WshShell.Run(sCmd, 1, true)\r\nWscript.Echo \"The task completed in \" &amp; Round(Timer - dtmStartTime, 2) &amp; \" seconds.\"<\/pre>\n<ol>\n<li>Copy the above code to Notepad<\/li>\n<li>Save the file as <code>exec_timer.vbs<\/code>.<\/li>\n<li>In the 2nd line that starts with <code>sCmd<\/code>, modify the program you want to run &#8212; i.e., replace <code>\"D:\\Batch Files\\Backup.bat\"<\/code> in the above example with the application or batch you want to run.<\/li>\n<li>Save the file and close Notepad.<\/li>\n<li>Double-click the VBScript file to run it.<\/li>\n<\/ol>\n<p>The VBScript launches the batch file, command, or the program. After it finishes running, the total execution time is shown (in seconds.)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10621\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/08\/find-execution-time-measure-2.png\" alt=\"measure total execution time of a command or program\" width=\"229\" height=\"133\" \/><\/p>\n<hr \/>\n<h3>Using TimeIt.exe from Resource Kit Tools<\/h3>\n<p><code>TimeIt.exe<\/code> is part of the Windows Server 2003 <a href=\"https:\/\/www.microsoft.com\/en-in\/download\/details.aspx?id=17657\" target=\"_blank\" rel=\"noopener noreferrer\">Resource Kit<\/a> (<a href=\"http:\/\/web.archive.org\/web\/20150401042827\/http:\/\/download.microsoft.com\/download\/8\/e\/c\/8ec3a7d8-05b4-440a-a71e-ca3ee25fe057\/rktools.exe\" rel=\"nofollow \">mirror link<\/a>) tool that shows the program or command execution timings. This program runs fine on Windows 10 as well.<\/p>\n<pre><strong>File info:<\/strong> rktools.exe - SHA256 - <a href=\"https:\/\/www.virustotal.com\/gui\/file\/6260d75a2cb30201c5424defec3ba505edb92b91802825e2fd6eb9bd58ed5cca\/detection\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">6260d75a2cb30201c5424defec3ba505edb92b91802825e2fd6eb9bd58ed5cca<\/a><\/pre>\n<ol>\n<li>After downloading the RK Tools, open rktools.exe using 7-Zip.<\/li>\n<li>Then, open inside <code>rktools.msi<\/code><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10623\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/08\/find-execution-time-measure-3.png\" alt=\"measure total execution time of a command or program\" width=\"337\" height=\"246\" \/><\/li>\n<li>Find <code>TimeIt.exe<\/code> and extract to a folder.<\/li>\n<\/ol>\n<p>To run a command or batch file and measure its total execution time, here are some examples:<\/p>\n<pre>timeit.exe ping google.com<\/pre>\n<pre>timeit.exe C:\\Batch Files\\Measure command run time\\backup.bat<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10622\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/08\/find-execution-time-measure-4.png\" alt=\"measure total execution time of a command or program\" width=\"699\" height=\"393\" \/><\/p>\n<p><strong>TimeIt<\/strong> showed the process exit time and elapsed time, among other details. When I checked, the <strong>bytes written<\/strong> value didn&#8217;t match with the output file size. But, the bytes read\/written info is not the subject of discussion in this article.<\/p>\n<h2>More Information<\/h2>\n<p>When writing the article about <a href=\"https:\/\/www.winhelponline.com\/blog\/convert-mp4-or-any-video-to-mp3-windows\/\">extracting audio from a video<\/a> file using the FFmpeg.exe, I thought of measuring the execution time of the command. I used the above script to measure the time taken to extract MP3 audio from a movie file using the FFmpeg.exe command-line tool.<\/p>\n<p>The 1st batch included this command-line:<\/p>\n<pre>ffmpeg -i \"C:\\Movies\\Movie.mp4\" -ss 01:20:00 -t 00:00:20 -codec:a libmp3lame -ab 128000 \"D:\\output-1.mp3\"<\/pre>\n<p>The 2nd batch included this command-line:<\/p>\n<pre>ffmpeg -ss 01:20:00 -i \"C:\\Movies\\Movie.mp4\" -t 00:00:20 -codec:a libmp3lame -ab 128000 \"D:\\output-2.mp3\"<\/pre>\n<p>As you can see, the number of command-line arguments and the respective values are exactly the same. The only difference is that the <code>-ss<\/code> (starting point) parameter is placed before the <code>-i<\/code> (file input) parameter, in the 2nd batch file. The method is called <strong>Input seeking<\/strong> as per <a href=\"https:\/\/trac.ffmpeg.org\/wiki\/Seeking\" target=\"_blank\" rel=\"noopener noreferrer\">FFmpeg.exe documentation<\/a>. The 1st method is called <strong>Output seeking<\/strong>, wherein the <code>-i<\/code> (input file) parameter appears before the <code>-ss<\/code> parameter.<\/p>\n<ul>\n<li>FFmpeg documentation says that the input seeking method is much faster than output seeking, because when using the former method, FFmpeg.exe jumps (seeks) directly to the mentioned Start point in the input file and starts decoding from that point onwards.<\/li>\n<li>Whereas, the output seeking method opens the file first, starts decoding from <code>00:00:00<\/code>, and then discards the data up until it reaches the <code>-ss<\/code> Start point <code>01:20:00<\/code>. So, the system resources (CPU, Memory, and Disk I\/O) are wasted as well as the execution time is increased when you use the Output seeking method.<\/li>\n<\/ul>\n<div class=\"rp\"><strong>RELATED:<\/strong> <a href=\"https:\/\/www.winhelponline.com\/blog\/convert-mp4-or-any-video-to-mp3-windows\/\">Convert MP4 or Any Video to MP3 (Extract Audio from Video file)<\/a><\/div>\n<p>The FFmpeg.exe documentation is correct. When I tested, the input seek ran much faster than the output seek method.<\/p>\n<ul>\n<li>The 1st command (Output seek) took 20.48 seconds to complete.<\/li>\n<li>The 2nd command (Input seek) took 16.62 seconds to complete.<\/li>\n<\/ul>\n<p>If you know any other methods to measure the execution time of a process, script, or command, let&#8217;s know.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You may sometimes want to to find the total execution time of a command or program you run. To optimize a script or program, it&#8217;s essential to know how long does it take for it to complete execution. This helps you compare the total run time of Program A vs. Program B and optimize your &#8230; <a title=\"Find the Total Execution Time of a Command or Program in Windows\" class=\"read-more\" href=\"https:\/\/www.winhelponline.com\/blog\/find-the-total-execution-time-of-command-program-windows\/\" aria-label=\"Read more about Find the Total Execution Time of a Command or Program in Windows\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[6,7],"tags":[106,396,480],"class_list":["post-10618","post","type-post","status-publish","format-standard","hentry","category-utilities","category-windows","tag-command-prompt","tag-powershell","tag-scripts"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":10243,"url":"https:\/\/www.winhelponline.com\/blog\/install-module-command-was-found-in-the-module-powershellget\/","url_meta":{"origin":10618,"position":0},"title":"Install-Module command was found in the module PowerShellGet","author":"Ramesh","date":"July 8, 2019","format":false,"excerpt":"PowerShell's Install-Module cmdlet downloads one or more modules from a repository and installs them on the local computer. But, when you run Install-Module, you may get the following error: Install-Module : The 'Install-Module' command was found in the module 'PowerShellGet', but the module could not be loaded. For more information,\u2026","rel":"","context":"In &quot;Windows 10&quot;","block_context":{"text":"Windows 10","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/windows-10\/"},"img":{"alt_text":"install-module command not found","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/powershell-install-module-error-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/powershell-install-module-error-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/powershell-install-module-error-1.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":28839,"url":"https:\/\/www.winhelponline.com\/blog\/cant-open-cmd-after-uninstalling-python-anaconda\/","url_meta":{"origin":10618,"position":1},"title":"Can&#8217;t Open CMD.exe After Uninstalling Python\/Anaconda; Exit Code 1","author":"Ramesh","date":"September 29, 2022","format":false,"excerpt":"After uninstalling Python\/Anaconda on your Windows computer, Command Prompt may not open. When you run cmd.exe, it flashes on the screen and immediately quits. Also, running DISM and SFC (to repair corrupt system files), repairing Windows installation, and running a thorough malware scan may not fix the issue. Also, when\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"vscode cmd.exe error 1","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2022\/09\/vscode-cmd-error-code-1.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":75380,"url":"https:\/\/www.winhelponline.com\/blog\/extend-windows-re-partition-powershell\/","url_meta":{"origin":10618,"position":2},"title":"How to Extend the Windows RE Partition Using PowerShell","author":"Ramesh","date":"June 3, 2024","format":false,"excerpt":"KB5034441 is a WinRE security update that patches the Winre.wim image. The Recovery partition needs 250 MB of free space for the KB5034441 update to install correctly. Almost every Windows 10 user has been affected by the KB5034441 error 0x80070643. You can extend the Recovery partition using the diskpart command-line.\u2026","rel":"","context":"In &quot;Windows 10&quot;","block_context":{"text":"Windows 10","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/windows-10\/"},"img":{"alt_text":"create folder - powershell","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2024\/06\/ps-create-folder.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2024\/06\/ps-create-folder.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2024\/06\/ps-create-folder.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2024\/06\/ps-create-folder.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":282,"url":"https:\/\/www.winhelponline.com\/blog\/create-system-restore-point-script-windows-10-8-7-vista-xp\/","url_meta":{"origin":10618,"position":3},"title":"How to Create System Restore Points using Script or Command-Line","author":"Ramesh","date":"May 16, 2008","format":false,"excerpt":"System Restore is a valuable feature in Windows that helps you easily recover the system in the event of any misconfiguration. If you've been using the System Restore feature regularly, then you need to know how to create System Restore Points with a single click using the command-line. You can\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"create restore point wmic shortcut","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2008\/05\/wmic-create-shortcut-2.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2008\/05\/wmic-create-shortcut-2.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2008\/05\/wmic-create-shortcut-2.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":5732,"url":"https:\/\/www.winhelponline.com\/blog\/replace-notepad-text-editor-notepad-plus-association\/","url_meta":{"origin":10618,"position":4},"title":"How to Replace Notepad With Notepad++ or Other Editor","author":"Ramesh","date":"November 2, 2017","format":false,"excerpt":"If you\u2019re looking at how to replace Notepad with Notepad++ or any third-party editor, this post explains how to do it. Notepad++ is a free source code editor and Notepad replacement that supports several languages. Let\u2019s see how you can replace Notepad with Notepad++ without replacing any system files. Notepad\u2026","rel":"","context":"In &quot;Utilities&quot;","block_context":{"text":"Utilities","link":"https:\/\/www.winhelponline.com\/blog\/category\/utilities\/"},"img":{"alt_text":"notepad plus replace debugger notepad.exe","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2017\/11\/debugger-notepad-plus-switch.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2017\/11\/debugger-notepad-plus-switch.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2017\/11\/debugger-notepad-plus-switch.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2017\/11\/debugger-notepad-plus-switch.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":425,"url":"https:\/\/www.winhelponline.com\/blog\/run-bat-files-invisibly-without-displaying-command-prompt\/","url_meta":{"origin":10618,"position":5},"title":"How to run .BAT files invisibly, without displaying the Command Prompt window","author":"Ramesh","date":"August 5, 2008","format":false,"excerpt":"Batch files (.BAT) and Windows NT Command Script (.CMD) files run in console window when double-clicked. This means that the Command Prompt window will be visible until the .BAT or .CMD file execution is complete. To make .BAT or .CMD file execution less intrusive, you can configure it to run\u2026","rel":"","context":"In &quot;Utilities&quot;","block_context":{"text":"Utilities","link":"https:\/\/www.winhelponline.com\/blog\/category\/utilities\/"},"img":{"alt_text":"run batch file hidden - nircmd exec","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2008\/08\/nircmd-batch-file-hidden.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts\/10618","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/comments?post=10618"}],"version-history":[{"count":0,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts\/10618\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/media?parent=10618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/categories?post=10618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/tags?post=10618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}