CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2005
    Posts
    3

    high performance counter?

    i need a high performance counter for my programm
    i wanted it to be crossplattform ... but thats the problem ...

    so can somebody give me good counters for windows and linux
    (plz several .. for choice .. or with pro and contra ...)

    i know QueryPerformanceCounter for windows ... but thats it =)

    would be nice if u post the frequency of the counter ... (and how to get it in code)
    Last edited by hydro; February 20th, 2005 at 08:56 AM.

  2. #2
    Join Date
    Dec 2004
    Location
    Poland
    Posts
    1,165

    Re: high performance counter?

    Maybe you will find something interesting here: http://www.codeguru.com/forum/showth...hreadid=291294
    B+!
    'There is no cat' - A. Einstein

    Use [code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: high performance counter?

    Well...there is basically no portable way since it depends on the underlying API...

  4. #4
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557

    Re: high performance counter?

    hydro,

    Indeed it is platform dependent. The following example might be useful for IA32 x86 with MSVC and GCC.

    The example has some related stuff from the class, but it's pretty clear how to deal with the assembly dialects alone.

    Good luck, Chris.



    Code:
    const ef_UINT64 e_float_cpu_ia32::tick(void) const
    {
      if(!supported())
      {
        return 0;
      }
      else
      {
        volatile ef_UINT32 lo = 0;
        volatile ef_UINT32 hi = 0;
    
        #if defined(USE_INTEL_x86_SYSTEM)
        
          #if defined(_MSC_VER)
    
            __asm
            {
              xor eax, eax
              cpuid
              rdtsc
              mov dword ptr lo, eax
              mov dword ptr hi, edx
            }
    
          #elif defined(__GNUC__)
          
            asm volatile("xorl %%eax, %%eax\n"
                         "cpuid\n"
                         "rdtsc\n"
                         "movl %%eax, %0\n"
                         "movl %%edx, %1" : "=g" (lo), "=g" (hi) : : "eax", "edx");
    
          #endif
        
        #endif
    
        return (static_cast<ef_UINT64>(hi) << 32) | lo;
      }
    }
    You're gonna go blind staring into that box all day.

  5. #5
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557

    Re: high performance counter?

    ... it's basically some of the stuff from the FAQ but augmented for GCC as well.

    Chris.
    You're gonna go blind staring into that box all day.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured