[Issue 6007] New: BigInt->string performance
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun May 15 10:00:11 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6007
Summary: BigInt->string performance
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2011-05-15 09:56:05 PDT ---
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
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list