Ryan Peschel
Ryan Peschel

Reputation: 11838

Fastest programming language for computing large numbers?

If I wanted to compute numbers with hundreds of millions of digits (positive integers), which programming language would be best suited for that?

Currently I'm using python and the script is running and it was easy to code, but I have concerns for its speed.

I don't really know much about assembly at all so while it MAY be the fastest, I would rather not use that. Is C the best choice here?

The specific operations I have to use are *, -, % (mod), exponentiation, equality testing (if statements), and basic looping and some sort of outputting capability (console output for example).

Many thanks.

Upvotes: 2

Views: 4030

Answers (3)

user922475
user922475

Reputation:

Here is your resource to read up on. This refutes the argument that C is fastest, unless you use the C99 restrict feature. If anything C++ is faster than C. It really comes down to the compiler understanding when two separate but sequential operations 'read' reference the same memory location. This allows the compiler to reorder the operations for optimization. It appears Fortran is best at doing this.

http://en.wikipedia.org/wiki/Pointer_aliasing

Also you can see here that Fortran blows C++ away at the Mandelbrot routine. But when it comes to text manipulation C++ appears to be tops.

http://shootout.alioth.debian.org/u32/fortran.php

Upvotes: 0

Pubby
Pubby

Reputation: 53097

GMP library with C/C++.

http://gmplib.org/

Upvotes: 2

Karoly Horvath
Karoly Horvath

Reputation: 96306

You can use GMP with plain C, but note that a lot of dynamic languages use it for arbitrary precision numbers, python too. You might not gain much by using C.

Upvotes: 4

Related Questions