How to get the efficiency of a thread in VC

Source: Internet
Author: User

// Define the start time
Large_integer FRE, star _, end _;
Queryperformancefrequency (& FRE );
Queryperformancecounter (& star _);

// Process ....
Pro (MB );

// Get the end time
Queryperformancecounter (& End _);
Ace_debug (lm_info, ace_text ("(% t) processing time % I/N "),
Long (end _. quadpart-star _. quadpart) * 10000/fre. quadpart )));

The printing time in this place is 1 unit of 0.1 milliseconds.

Ace_hrtime_t starttime = ace_ OS: gethrtime ();

Ace_inline ace_hrtime_t
Ace_ OS: gethrtime (const ace_hrtimer_op OP)
{
Ace_ OS _trace ("ace_ OS: gethrtime ");
# If defined (ace_has_hi_res_timer)
Ace_unused_arg (OP );
Return: gethrtime ();
# Elif defined (ace_has_aix_hi_res_timer)
Ace_unused_arg (OP );
Timebasestruct_t TB;

: Read_real_time (& TB, timebase_sz );
: Time_base_to_time (& TB, timebase_sz );

Return ace_hrtime_t (Tb. tb_high) * ace_one_second_in_nsecs + Tb. tb_low;
# Elif defined (ace_win32)
Ace_unused_arg (OP );
Large_integer freq;

: Queryperformancecounter (& freq );

# If defined (ace_lacks_longlong_t)
Ace_uint64 uint64_freq (freq. U. lowpart,
Static_cast <unsigned int> (freq. U. highpart ));
Return uint64_freq;
# Else
Return freq. quadpart;
# Endif // ace_lacks_longlong_t
# Elif defined (GHS) & defined (ace_has_pentium)
Ace_unused_arg (OP );
// Use. OBJ/gethrtime. O, which was compiled with G ++.
Return ace_gethrtime_name ();
# Elif (defined (_ gnug _) | defined (_ intel_compiler ))&&! Defined (ace_vxworks) & defined (ace_has_pentium)
Ace_unused_arg (OP );
# If defined (ace_lacks_longlong_t)
Double now;
# Else /*! Ace_lacks_longlong_t */
Ace_hrtime_t now;
# Endif /*! Ace_lacks_longlong_t */

// Read the high-res tick counter directly into memory variable "now ".
// The a constraint signifies a 64-bit Int.
ASM volatile ("rdtsc": "= A" (now): "Memory ");

# If defined (ace_lacks_longlong_t)
Ace_uint32 least, most;
Ace_ OS: memcpy (& least, & now, sizeof (ace_uint32 ));
Ace_ OS: memcpy (& most, (u_char *) & now + sizeof (ace_uint32 ),
Sizeof (ace_uint32 ));

Ace_hrtime_t RET (least, most );
Return ret;
# Else /*! Ace_lacks_longlong_t */
Return now;
# Endif /*! Ace_lacks_longlong_t */
# Elif defined (Linux) & defined (ace_has_alpha_timer)
// Note: Alphas only have a 32 bit tick (cycle) counter. The RPCC
// Instruction actually reads 64 bits, but the high 32 bits are
// Implementation-specific. Linux and Digital UNIX, for example,
// Use them for virtual tick counts, I. e., taking into account only
// The time that the process was running. This information is from
// David mosberger's article, see comment below.
Ace_uint32 now;

// The following statement is based on Code published:
// Mosberger, David, "How to make your applications fly, Part 1 ",
// Linux journal issue 42, October 1997, page 50. It reads
// High-res tick counter directly into the memory variable.
ASM volatile ("RPCC % 0": "= r" (now): "Memory ");

Return now;
# Elif defined (ace_has_powerpc_timer) & (defined (GHS) | defined (_ gnug __))
// PowerPC w/greenhills or G ++.

Ace_unused_arg (OP );
U_long most;
U_long least;

# If defined (GHS)
Ace_ OS: readppctimebase (most, least );
# Else
U_long scratch;

Do {
ASM volatile ("mftbu % 0/N"
"Mftb % 1/N"
"Mftbu % 2"
: "= R" (MOST), "= r" (least), "= r" (Scratch ));
} While (most! = Scratch );
# Endif

# If defined (ace_lacks_longlong_t)
Return ace_u_longlong (least, most );
# Else /*! Ace_lacks_longlong_t */
Return 0x00000000llu * Most + least;
# Endif /*! Ace_lacks_longlong_t */

# Elif defined (ace_has_clock_gettime)
// E.g., VxWorks (besides PowerPC & greenhills )...
Ace_unused_arg (OP );
Struct timespec ts;

Ace_ OS: clock_gettime (
# If defined (ace_has_clock_gettime_monotonic)
Clock_monotonic,
# Endif /*! Ace_has_clock_gettime_monotonic */
Clock_realtime,
& TS );

// Carefully create the return value to avoid Arithmetic overflow
// If ace_hrtime_t is ace_u_longlong.
Return static_cast <ace_hrtime_t> (TS. TV _sec )*
Ace_u_one_second_in_nsecs + static_cast <ace_hrtime_t> (TS. TV _nsec );
# Else
Ace_unused_arg (OP );
Ace_time_value const now = ace_ OS: gettimeofday ();

// Carefully create the return value to avoid Arithmetic overflow
// If ace_hrtime_t is ace_u_longlong.
Return (static_cast <ace_hrtime_t> (now. Sec () * (ace_uint32) 1000000 +
Static_cast <ace_hrtime_t> (now. USEC () x (ace_uint32) 1000;
# Endif/* ace_has_hi_res_timer */
}

 

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.