in reply to Re^3: Class::Std::Fast cache and threads
in thread Class::Std::Fast cache and threads
You may have missed is that it's caching a blessed scalar ref, which means that on the next new call, it can just pop an item of the cache instead of blessing a new object.
Blessing a ref takes an infinitesimal amount of time. My benchmark:
package STR; use Class::Std::Fast; ## cache => 1; package main; use Time::HiRes qw[ time ]; my $start = time; STR->new for 1 .. 1e6; printf "Took %.8f seconds\n", ( time - $start ) / 1e6; __END__ ## With caching c:\test>junk64 Took 0.00002447 seconds ## Without caching c:\test>junk64 Took 0.00002391 seconds
And if you removed all the cache related conditionals, it would be quicker still.
It would also avoid your original problem
|
|---|