Just another idea...
use constant TEST_NOCACHE => $ENV{TEST_NOCACHE}; sub foo ($) { my $arg = shift; state %cache; return $cache{$arg} if !TEST_NOCACHE && exists $cache{$arg}; my $result = ... something costly ...; $cache{$arg} = $result; }
Thanks to constant folding, the above compiles identically as the original code under normal circumstances, and all effects of the cache are removed when the flag is true.
The effect of the cache can be observed by finding the difference between runs of
TEST_NOCACHE=0 cache.t
and
TEST_NOCACHE=1 cache.t
In reply to Re: How to test caching?
by ikegami
in thread How to test caching?
by JavaFan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |