Win32::PerfCounter - Use Windows' high performance counter


Win32-PerfCounter documentation  | view source Contained in the Win32-PerfCounter distribution.

Index


NAME

Top

Win32::PerfCounter - Use Windows' high performance counter

SYNOPSIS

Top

  use Win32::PerfCounter qw(:all)
  # equivalent to 
  use Win32::PerfCounter qw(frequency counter)

  my $freq  = [ frequency() ]

  my $start = [ counter() ]
  do_sth();
  my $stop  = [ counter() ]

  use Time::HiRes qw(tv_interval);

  my $counter_per_second = tv_interval([0, 0], frequency());
  my $duration = tv_interval($start, $stop) / $counter_per_second;

  print "Something took $duration seconds to complete.\n";

ABSTRACT

Top

Use Windows' high performance counter

DESCRIPTION

Top

The Win32 API features a high performance counter that allows measuring extremely short time spans. Depending on your machine, the resolution should be around 1 microsecond (1 second = 1_000_000 microseconds). This module is an interface to the Win32 API functions QueryPerformanceCounter and QueryperformanceFrequency that implement this counter.

Returns the resolution of the high performance counter in counter events per second, as an array of two integers (high and low part of an 64 bit integer). Returns undef if the high performance counter is not available on this machine. According to the Windows API specification, the return value of frequency is constant while the machine is running.

Returns the current value of the high performance counter, as an array of two integers (high and low part of an 64 bit integer). Returns undef if the high performance counter is not available on this machine. Note that the results need to be divided by the frequency first to be useful.

HINT

Top

The return values used in this module are compatible with Time::HiRes::tv_interval. Nice if you're lazy like me and don't want to do the calculations yourself. You can even convert frequency's return value into a floating point value as shown in the synopsis.

CAVEAT

Top

Obviously, the XS call adds some overhead. If you want to get more exact results, you should measure the overhead of calling the counter() function and subtract it from the results.

SEE ALSO

Top

WinBase.h, Windows.h, L(Time::HiRes|Time::HiRes).

AUTHOR

Top

Christian Renz, <crenz @ web42.com>

COPYRIGHT AND LICENSE

Top


Win32-PerfCounter documentation  | view source Contained in the Win32-PerfCounter distribution.