Implementing the Clocking feature under Windows batch processing

Source: Internet
Author: User

Sometimes after performing a batch of windows, you want to know how much time this process takes, and if the C code under Windows can call GetTickCount () before and after the procedure, then subtract to get the time it takes.

But if there is no such ready-made function in batch processing, and I have been looking for a long time on the internet did not find. Finally, after the batch processing variable calculation is taken, and the return value is obtained from EXE, the function is finally realized.

Evaluate in batches

The following code will print out the 20

1 @echo off2 set cho=233 set/a res=%cho%-34 Echo%res%

Note that after the first set = Must not be preceded by a space, the second set must have A/a

Get the return value of EXE

With%errorlevel% you can get the return value after executing an EXE.

/wait Program.exeset r=%errorlevel%%r%

GetTickCount Program

Write a simple C program that calls GetTickCount () to return its value

#include <windows.h><stdio.h>int main (intChar* * argv) {     int t = GetTickCount ();    printf ("%d\n", T);     return t;}

Arbitrarily use a C compiler, the above C source code compiled into EXE program, named GetTickCount.exe, and put it into a system path.

Application
/wait GetTickCount.exeset t1=%errorlevel%3
:: TODO Something
/wait GetTickCount.exeset t2=%errorlevel%set/a t=%t2%-%t1%echo%t%

The time spent in milliseconds is finally printed.

Download path for GetTickCount Http://files.cnblogs.com/files/xiangism/GetTickCount.rar

Bash in Linux for timing

By the way, how to implement timing in a shell under Linux

#!/bin/bashstart=$ (date"+%s") # do something  sleep2now =$ (date"+%s")  Time =$ (now-start) echo"timeused: $time seconds "

~~~~eureka~~~~

Implementing the Clocking feature under Windows batch processing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.