-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
for loops for bigint is very slow #143
Comments
Please share the Python and Julia code. This huge time is due to the initialisations (initBigInt) inside the for loop. I do not know about Julia, but Python has a native support for multiprecision integers with fast simple multiplication integers (Karatsuba). If you really need to compute factorials fast and efficiently for your application, consider using e.g. Pari/GP or Sagemath or any good formal computer library. |
Thank you very much! I am just a beginner of Nim. So, this is a toy test. I didn't optimize the julia codes or python codes. let
x::BigInt = 1
@time for i in 1:99999
x *= i
end
println
end x = 1
for i in range(1,100000):
x = x * i
print(x) I tried to use the bignum, but always errors...so, thank you again! |
Note that when compiling with the -d:danger flag, timings on my machine went from 23 seconds to 8 seconds. import bigints
var x:BigInt = 1.initBigInt
var counter = 1.initBigInt
for i in 1 .. 99998:
x *= counter
counter.inc
x *= counter
echo x |
Great! I think bigints or Nim need more optimizations...I will return to check it in future! |
in Nim 2.0
takes about 19 seconds in my computer, but Python 3.10 and Julia 1.6.7 only takes less than 2 seconds...
The text was updated successfully, but these errors were encountered: