Gets the amount of CPU time that a function execution completes in a thread.

Source: Internet
Author: User
Tags filetime

Refer to Windows core programming (fifth edition)

_ Int64 filetimetoquadword (pfiletime PFT)
{
// Convert filetime into _ int64 data
Return (int64shllmod32 (PFT-> dwhighdatetime, 32) | PFT-> dwlowdatetime );
}

Void merge mlongoperation ()
{
Filetime ftkerneltimestart, ftkerneltimeend;
Filetime ftusertimestart, ftusertimeednd;
Filetime ftdummy;

_ Int64 qwkerneltimeelapsed, qwusertimeelapsed, qwtotaltimeelapsed;

Getthreadtimes (getcurrentthread (), & ftdummy, & ftdummy,
& Ftkerneltimestart, & ftusertimestart );

Func (); // calculate the amount of CPU time required by the function

 

Getthreadtimes (getcurrentthread (), & ftdummy, & ftdummy,
& Ftkerneltimeend, & ftusertimeednd );
 
// The time used by the kernel. The absolute value of the time used by the operating system code in kernel mode for thread execution, in the unit of NS
Qwkerneltimeelapsed = filetimetoquadword (& ftkerneltimeend)
-Filetimetoquadword (& ftkerneltimestart );
// User time, the absolute value of the time used by the thread to execute the function, in the unit of 100ns
Qwusertimeelapsed = filetimetoquadword (& ftusertimeednd)
-Filetimetoquadword (& ftusertimestart );
// The total CPU time obtained by the previous function
Qwtotaltimeelapsed = qwkerneltimeelapsed + qwusertimeelapsed;

}

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.