NAME

Cache::Profile - Measure the performance of a cache

VERSION

version 0.06

SYNOPSIS

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;

DESCRIPTION

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.

METHODS

AUTOLOAD

Delegates everything to the cache.

get
set
compute

Standard cache API methods.

report

Returns a simple report as a human readable string.

{average,total}_{real,cpu}_time_{get,set,miss,all}

Returns the time value (as floating seconds) for the given method.

miss is the time value for the callback provided to compute.

compute is counted as a get, optionally followed by a miss and a set.

call_count_{get,set,miss,all}

Returns the number of times a method is called.

query_count

Returns the number of queried keys. For caches supporting multi key get this may be bigger than call_count_get.

hit_rate
miss_count

Returns the number of keys whose corresponding return values from get were defined or undef, respectively.

speedup

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.

reset

Resets the counters/timers.

SUPPORT

Bugs may be submitted through the RT bug tracker (or bug-Cache-Profile@rt.cpan.org).

AUTHOR

יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>

CONTRIBUTOR

Karen Etheridge <ether@cpan.org>

COPYRIGHT AND LICENCE

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.