Win32::PerfCounter - Use Windows' high performance counter
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";
Use Windows' high performance counter
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.
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.
Time::HiRes::tv_interval
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.
counter()
WinBase.h, Windows.h, L(Time::HiRes|Time::HiRes).
Christian Renz, <crenz @ web42.com>
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:
'=item' outside of any '=over'
You forgot a '=back' before '=head1'
To install Win32::PerfCounter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Win32::PerfCounter
CPAN shell
perl -MCPAN -e shell install Win32::PerfCounter
For more information on module installation, please visit the detailed CPAN module installation guide.