Issue 6007 - BigInt->string performance
Summary: BigInt->string performance
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords: bootcamp
Depends on:
Blocks:
 
Reported: 2011-05-15 09:56 UTC by bearophile_hugs
Modified: 2024-12-01 16:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-05-15 09:56:05 UTC
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
Comment 1 dlangBugzillaToGithub 2024-12-01 16:14:08 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9904

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB