How to get the clock accuracy in one thousandth of a second

Source: Internet
Author: User

Typedef struct _ binint32

{

_ Int32 i32 [2];

} Bigint32;

Typedef struct _ bigint64

{

_ Int64 i64;

} Bigint64;

Typedef union _ bigint

{Bigint32 int32val;

Bigint64 int64val;

} Bigint;
The following code obtains the high and low clock counters from the operating system. Fill in two 32-bit sections of _ int64 data respectively:

Bigint start_ticks, end_ticks;

_ ASM {

Rdtsc

MoV start_ticks.int32val.i32 [0], eax

MoV start_ticks.int32val.i32 [4], EDX

}
 
Rdtsc (read time stamp counter) is an assembly instruction that loads the content of the timestamp counter into the eax and EDX registers. After the code is executed, start_ticks contains the complete clock count. Call the above Code again, replace start_ticks with end_ticks, and subtract start_ticks from end_ticks to get the clock cycle that passes during the two calls.

 

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.