Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Math-Random-Secure CPAN distribution.

Report information
The Basics
Id: 64370
Status: resolved
Priority: 0/
Queue: Math-Random-Secure

People
Owner: Nobody in particular
Requestors: chip [...] pobox.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.03
Fixed in: 0.05



Subject: too many method calls
To get one random number, at least four method calls are made before you even get to ISAAC. Shirley, that could be reduced to zero or, perhaps, one. Just a matter of moving the ISAAC API pointer up into an attribute of the Math::Random::Secure object. Does the RNG object even have to exist as a separate object?
Hey Chip. Thanks for the bug report. I understand your concern, but I assure you that the number of method calls within Math::Random::Secure::RNG is nothing compared to the number of calls and activity performed by the dependent modules, not to mention that the method calls themselves don't occupy any significant part of the profile (unless you have a profile that shows otherwise, which I'd be happy to see). The RNG is a separate object for lots of good reasons, not the least among them being the software design of the system. But it's also handy for people who want an object or who want to change the fashion in which the RNG works (perhaps to make it more secure). Currently, on my Core 2 Duo 2.66Ghz Math::Random::Secure generates about 250,000 random numbers per second with Math::Random::ISAAC::XS installed. So if that's a bottleneck for a system using the module, then I suspect they're at the point where they would need to write their own C or XS code anyway (or perhaps switch to a compiled language completely).
Okay, after I wrote this, I did a bit of testing, and it does indeed get significantly faster (up to 320,000 random numbers per second) on my machine with a few of the levels of indirection removed. I see a good way to do that and retain the software design reasonably, so I may go ahead and do that.
From: chip [...] pobox.com
On Mon Jan 03 02:06:04 2011, MKANAT wrote: Show quoted text
> Okay, after I wrote this, I did a bit of testing, and it does indeed > get significantly faster (up to 320,000 random numbers per second) on
my Show quoted text
> machine with a few of the levels of indirection removed. I see a good
way Show quoted text
> to do that and retain the software design reasonably, so I may go ahead > and do that.
A cached weak reference and a cached code reference should take care of it, if you're just too attached to the current class hierarchy to change it.
Okay, this is fixed now, and the code runs about 2.5x faster than it used to--I now get about 620,000 random numbers per second on my machine. It's still not as fast as directly using Math::Random::ISAAC::XS, but it retains its flexibility, I've eliminated most method calls, and it's much faster than it used to be.
From: chip [...] pobox.com
On Fri Jan 07 06:32:18 2011, MKANAT wrote: Show quoted text
> Okay, this is fixed now, and the code runs about 2.5x faster than it
used Show quoted text
> to--I now get about 620,000 random numbers per second on my machine.
It's Show quoted text
> still not as fast as directly using Math::Random::ISAAC::XS, but it > retains its flexibility, I've eliminated most method calls, and it's
much Show quoted text
> faster than it used to be.
Cool beans! Thanks much