Skip to content
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

BigInt->string performance #9904

Open
dlangBugzillaToGithub opened this issue May 15, 2011 · 0 comments
Open

BigInt->string performance #9904

dlangBugzillaToGithub opened this issue May 15, 2011 · 0 comments

Comments

@dlangBugzillaToGithub
Copy link

bearophile_hugs reported this on 2011-05-15T09:56:05Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=6007

CC List

Description

This single-line Haskell code runs in about 0.04 seconds compiled with GHC -O3:

main = print $ (5^4^3^2) `mod` 10


This D2 code runs in about 0.09 seconds (DMD 2.053) showing that this computation is fast enough in D (GHC used GNU multiprecision):

import std.stdio, std.bigint;
void main() {
  writeln((BigInt(5) ^^ 4 ^^ 3 ^^ 2) % 10);
}



This Haskell program runs in about 0.24 seconds (GHC -O3), and prints pieces of the number:

y = show ( 5^4^3^2 )
l = length y

main = do
    putStrLn ("5**4**3**2 = " ++ take 20 y ++ "..." ++ drop (l-20) y ++ " and has " ++ show l ++ " digits")


A similar D2 program takes about 3.38 seconds, so I think the BigInt->string conversion is significantly slower:

import std.stdio, std.bigint;
void main() {
  auto s = toDecimalString(BigInt(5) ^^ 4 ^^ 3 ^^ 2);
  writefln("5^4^3^2 = %s..%s (%d digits)", s[0..20], s[$-20..$], s.length);
}


Some info about a proposal to speed up Python division and int->str conversions:
http://fredrik-j.blogspot.com/2008/07/making-division-in-python-faster.html
http://bugs.python.org/issue3451
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants