Cache::Profile - Measure the performance of a cache
version 0.04
my $cache = Cache::Profile->new( cache => $real_cache, # CHI, Cache::FastMmap, Cache::Ref, etc ); # use normally: $cache->set( foo => "bar" ); $cache->get("foo"); # if you want to count speedup, use CHI's compute method: $cache->compute( $key, sub { # compute the value for $key, this is called on miss return something(); }); # on caches that don't support 'compute' use Cache::Profile::CorrelateMissTiming # it measures the elapsed time between subsequent calls to `get` and `set` # with the same key (only on a cache miss) Cache::Profile::CorrelateMissTiming->new( cache => Cache::FastMmap->new ); # print a short stat report: warn $cache->report; # or check stats manually: $cache->hit_rate; # compare various caches to pick the best one: $cmp = Cache::Profile::Compare->new( caches => [ Cache::Foo->new, Cache::Bar->new, ], ); $cmp->set( foo => "bar" ); $cmp->get("foo"); warn $cmp->report;
This modules provide a wrapper object for various caching modules (it should work with most caching modules on the CPAN).
The idea is to measure the performance of caches (both timing info and hit/miss rates), in order to help make an informed decision on whether caching is really worth it, and to decide between several caches.
Note that this should increase the overhead of caching by a bit while in use, especially for quick in memory caches, so don't benchmark with profiling in case.
Delegates everything to the cache.
Standard cache API methods.
Returns a simple report as a human readable string.
Returns the time value (as floating seconds) for the given method.
miss is the time value for the callback provided to compute.
miss
compute
compute is counted as a get, optionally followed by a miss and a set.
get
set
Returns the number of times a method is called.
Returns the number of queried keys. For caches supporting multi key get this may be bigger than call_count_get.
call_count_get
Returns the number of keys whose corresponding return values from get were defined or undef, respectively.
undef
Returns the actual time elapsed using caching divided the estimated time to compute all values (based on the average time to compute cache misses).
Smaller is better.
If the overhead of get and set is higher, this will be bigger than 1.
Resets the counters/timers.
Bugs may be submitted through the RT bug tracker (or bug-Cache-Profile@rt.cpan.org).
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
Karen Etheridge <ether@cpan.org>
This software is copyright (c) 2010 by יובל קוג'מן (Yuval Kogman).
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Cache::Profile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Cache::Profile
CPAN shell
perl -MCPAN -e shell install Cache::Profile
For more information on module installation, please visit the detailed CPAN module installation guide.