Christian Renz

NAME

Win32::PerfCounter - Use Windows' high performance counter

SYNOPSIS

  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

Use Windows' high performance counter

DESCRIPTION

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.

frequency

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.

counter

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

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

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

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

AUTHOR

Christian Renz, <crenz @ web42.com>

COPYRIGHT AND LICENSE

Copyright 2003-2005 by Christian Renz <crenz @ web42.com>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 55:

'=item' outside of any '=over'

Around line 63:

You forgot a '=back' before '=head1'