开发者

Fastest programming language for computing large numbers?

开发者 https://www.devze.com 2023-04-09 11:59 出处:网络
If I wanted to compute numbers with hundreds of millions of digits (positive integers), which programming language would be best suited for that?

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 output开发者_运维技巧ting capability (console output for example).

Many thanks.


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.


GMP library with C/C++.

http://gmplib.org/


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号