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

Source: Internet
Author: User
Tags sleep function

# Include <stdio. h>
# Include <sys/time. h>
# Include <time. h>

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 those in wimdows are 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.

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.