Clock Cycle Measurement


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Clock Cycle Measurement

  1. #1
    Join Date
    Apr 2007
    Posts
    68

    Clock Cycle Measurement

    something i found interesting to share:
    ------------------------------------------------------------
    //#put above main
    extern __inline__ unsigned long long int rdtsc()
    {
    unsigned long long int x;
    __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
    return x;
    }

    //#inside main
    //#declare on top
    unsigned long start, end;
    //#before manipulation
    start = rdtsc();
    //#after manipulation
    end = rdtsc();
    //#to see output
    cout << "Running Time : "
    << end - start << endl;

    ------------------------------------------------------------

    u may try to use above partion of code to measure clock cycles needed to execute ur code. its sumthing similary to ordinary timer used in c++

  2. #2
    Join Date
    Dec 2003
    Posts
    3,366
    be careful with it, some newer cpu's vary their clock speed so clock cycles measured with the time stamp register are no longer directly one to one mapped to the CPU frequency for all machines.

Similar Threads

  1. Help with Error in class
    By velkropie in forum Java
    Replies: 5
    Last Post: 03-24-2007, 11:09 AM
  2. Clock using C++ & DirectX
    By Arkanops in forum C++
    Replies: 3
    Last Post: 04-14-2006, 03:44 AM
  3. LengthConverter
    By k_o_bliss in forum Java
    Replies: 1
    Last Post: 08-16-2005, 08:44 AM
  4. PC CLOCK SYNCHRONIZING USING VISUAL BASIC
    By Al Rest in forum vb.announcements
    Replies: 0
    Last Post: 06-10-2002, 03:19 AM
  5. drwas a clock
    By zainorin in forum Java
    Replies: 0
    Last Post: 08-01-2000, 09:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center