Syntactic Confectionery Delight  
PerlMonks 
Re: Re: Favourite modules April 2003by BrowserUk (Pope) 
on Apr 16, 2003 at 06:34 UTC ( #250802=note: print w/ replies, xml )  Need Help?? 
Just a word of caution to anyone seduced by the power of Quantum::Superpositioning (as I was around 10 months ago:) : Quick, it ain't; Memory hungry it is. It's a fun, and very powerful demonstraton of some powerful concepts, but using it in workaday code is costly. To demonstrate that, I reimplemented the brute force algorithms shown in the Q::S pod for is_prime(), factors() and GCD() using fairly standard perl, and the result show that this is not permature microoptimisation I am talking about: The benchmark
The results
To put that into perspective, the nonQ::S version of is_prime() will find the 9592 prime < 100,000 in approximately half the time the Q::S version finds the 1229 < 10,000. The non Q::S version of factors() will find the approx: 400,000 factors of 2!..9! in around a 5th of the time required by the Q::S version to find the approx 6000 factors of 2! .. 6!. And The nonQ::S version will perform the approx: 400,000 divisions and int's and the approx: 800,000 comparisons involved in finding the GCD() (using this algorithm) between each succesive pair of factorial 2! thru 9! in about 1/5th the time taken for the Q::S version to do the (approx) 12,000 divisions, 6,000 int's and 12,000 comparisons. Even when used for simple testing of arrays against constants Eg.if (all(@array) != 1) {...) the overheads are quite heavy and can quite quickly invoke swapping if your arrays are of any size. Hopefully, once the functionality is moved into the core as C or XS, this caveat will disappear. Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong. 2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible 3) Any sufficiently advanced technology is indistinguishable from magic. Arthur C. Clarke.
In Section
Meditations

