How do I measure execution time of a command on the Windows command line?

后端 未结 30 2940
南笙
南笙 2020-11-22 09:44

Is there a built-in way to measure execution time of a command on the Windows command line?

相关标签:
30条回答
  • 2020-11-22 09:57

    I'm using Windows XP and for some reason timeit.exe does not work for me. I found another alternative - PTIME. This works very well.

    http://www.pc-tools.net/win32/ptime/

    Example -

    C:\> ptime
    
    ptime 1.0 for Win32, Freeware - http://www.pc-tools.net/
    Copyright(C) 2002, Jem Berkes <jberkes@pc-tools.net>
    
    Syntax: ptime command [arguments ...]
    
    ptime will run the specified command and measure the execution time
    (run time) in seconds, accurate to 5 millisecond or better. It is an
    automatic process timer, or program timer.
    
    
    C:\> ptime cd
    
    ptime 1.0 for Win32, Freeware - http://www.pc-tools.net/
    Copyright(C) 2002, Jem Berkes <jberkes@pc-tools.net>
    
    ===  cd ===
    C:\
    
    Execution time: 0.015 s
    
    0 讨论(0)
  • 2020-11-22 09:58
    1. In the directory where your program is, type notepad mytimer.bat, click 'yes' to create a new file.

    2. Paste the code below, replacing YourApp.exe with your program, then save.

      @echo off
      date /t
      time /t
      YourApp.exe
      date /t
      time /t
      
    3. Type mytimer.bat in the command line then press Enter.

    0 讨论(0)
  • 2020-11-22 09:59

    I use freeware called "GS Timer".

    Just make a batch file like this:

    timer
    yourapp.exe
    timer /s
    

    If you need a set of times, just pipe the output of timer /s into a .txt file.

    You can get it here: Gammadyne's Free DOS Utilities


    The resolution is 0.1 seconds.

    0 讨论(0)
  • 2020-11-22 09:59

    Depending on the version of Windows you're using, just running bash will put you into Bash mode. This will allow you to use a bunch of commands that are not available on PowerShell directly (like the time command). Timing your command is now as easy as executing:

    # The clause <your-command> (without the angle brackets) denotes the command you want to run.
    $ time <your-command>
    

    Note: You can easily quit from Bash mode and return back into your mainstream shell by running exit while in Bash mode.

    This worked for me perfectly (Windows 10) after trying out other methods (like Measure-Command) which sometimes produce undesired stats. Hope this works for you as well.

    0 讨论(0)
  • 2020-11-22 09:59

    Having Perl installed the hires solution available, run:

    C:\BATCH>time.pl "echo Fine result"
    0.01063
    Fine result
    

    STDERR comes before measured seconds

    #!/usr/bin/perl -w
    
    use Time::HiRes qw();
    my $T0 = [ Time::HiRes::gettimeofday ];
    
    my $stdout = `@ARGV`;
    
    my $time_elapsed = Time::HiRes::tv_interval( $T0 );
    
    print $time_elapsed, "\n";
    print $stdout;
    
    0 讨论(0)
  • 2020-11-22 10:00

    If you are using Windows 2003 (note that windows server 2008 and later are not supported) you can use The Windows Server 2003 Resource Kit, which contains timeit.exe that displays detailed execution stats. Here is an example, timing the command "timeit -?":

    C:\>timeit timeit -?
    Invalid switch -?
    Usage: TIMEIT [-f filename] [-a] [-c] [-i] [-d] [-s] [-t] [-k keyname | -r keyname] [-m mask] [commandline...]
    where:        -f specifies the name of the database file where TIMEIT
                     keeps a history of previous timings.  Default is .\timeit.dat
                  -k specifies the keyname to use for this timing run
                  -r specifies the keyname to remove from the database.  If
                     keyname is followed by a comma and a number then it will
                     remove the slowest (positive number) or fastest (negative)
                     times for that keyname.
                  -a specifies that timeit should display average of all timings
                     for the specified key.
                  -i specifies to ignore non-zero return codes from program
                  -d specifies to show detail for average
                  -s specifies to suppress system wide counters
                  -t specifies to tabular output
                  -c specifies to force a resort of the data base
                  -m specifies the processor affinity mask
    
    Version Number:   Windows NT 5.2 (Build 3790)
    Exit Time:        7:38 am, Wednesday, April 15 2009
    Elapsed Time:     0:00:00.000
    Process Time:     0:00:00.015
    System Calls:     731
    Context Switches: 299
    Page Faults:      515
    Bytes Read:       0
    Bytes Written:    0
    Bytes Other:      298
    

    You can get TimeIt in the Windows 2003 Resource Kit. It's not available for direct download from the Microsoft Download Center, but one can still get it from the arhive.org - Windows Server 2003 Resource Kit Tools.

    0 讨论(0)
提交回复
热议问题