In LINUX, the system time (in milliseconds) and the computing program running time are used.

Source: Internet
Author: User
Tags sleep function
In LINUX, the system time (in milliseconds) and the computing program running time-Linux general technology-Linux programming and kernel information are obtained. The following is a detailed description. # Include
# Include
# Include


Struct timeval tvpre, tvafter;
Gettimeofday (& tvpre, NULL );
Sleep (3); // This is linux programming. This sleep is in seconds.
Gettimeofday (& tvafter, NULL );

Ast_log (LOG_NOTICE, "prepaid_staff_log: test spend time is % d msecond. \ n", (tvafter. TV _sec-tvpre. TV _sec) * 1000 + (tvafter. TV _usec-tvpre. TV _usec)/1000 );


The output is 3002 milliseconds. Here, we need to know that the sleep function parameters in LINUX are measured in seconds, while that in wimdows is measured in milliseconds.

Note that the sleep function in linux is not accurate. Don't rely on it when you need to be very accurate.
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.