Using the RDTSC (read-timestamp counter) instruction to monitor performance

Source: Internet
Author: User
Code:
#include <sys/time.h>
#include <time.h>
#include <stdio.h>
typedef unsigned Long Long Ticks;

Static __inline__ ticks getticks (void)
{
     unsigned a, D;
     ASM ("Cpuid");
     ASM volatile ("RDTSC": "=a" (a), "=d" (d));

     Return (((ticks) a) | ((ticks) (d) <<));
}
int main () {
     int r = 0;
     Ticks Tick,tick1,tickh;
   Unsigned long long time  =0;

     Tick = Getticks ();
   
     Sleep (a);
   
     Tick1 = Getticks ();
   
     Time = (unsigned) ((Tick1-tick)/1662543);
    printf ("/ntime in MS%llu/n", time);
return 0;
}

Cat/proc/cpuinfo gives Code:

pprocessor:0 Vendor_id:genuineintel CPU Family:6 model name : Genuine Intel (R) CPU T2300 @ 1.66GHz stepping:8 CPU mhz:1662.543 Cache size:20 KB fdiv_bug:no hlt_bug:no f00f_bug:no coma_bug:no fpu:yes fpu_except Ion:yes cpuid level:10 wp:yes flags:fpu vme de PSE TSC MSR PAE MCE cx8 APIC Sep MTRR PGE MCA cm         OV Pat Clflush DTS ACPI MMX FXSR SSE SSE2 SS TM Pbe constant_tsc up Arch_perfmon BTS pni monitor VMX est tm2 xtpr bogomips : 3328.87 Clflush size:64 

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.