CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
BigInt speed

 



dbaugh
New User

Oct 24, 2011, 9:30 PM

Post #1 of 2 (875 views)
BigInt speed Can't Post

Hi,

This is my first post on this forum. Be gentle.

I am reading hundreds of millions of 12 digit numbers from files. I then square the numbers and keep a counter of how many I have read in. When I get an interesting result, like the last number in a given file or the millionth number, I square it and add it to a 24 digit constant. I then print the result to the screen along with the count so far. As an aside, I would prefer to write it to a file, but I can probably figure that out.

Perl does all of this very quickly. The results are wrong. If I put in a use BigInt the results are correct and the speed slows to a crawl. I think it is probably treating every variable like it is a big integer when I only need it for the squared sum and certainly not for the running count.

How do I only suffer the speed penalty of BigInt where it is necessary? Or, is there an entirely different better way to do this?

Thanks,

David


rovf
Veteran

Oct 25, 2011, 7:59 AM

Post #2 of 2 (835 views)
Re: [dbaugh] BigInt speed [In reply to] Can't Post


Quote
I think it is probably treating every variable like it is a big integer when I only need it for the squared sum and certainly not for the running count.


In this case, I suggest to use Math::BigInt instead of BigInt.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives