develooper Front page | perl.perl5.porters | Postings from January 2005

RFC: Math::BigInt Calc vs. FastCalc

Thread Next
From:
Tels
Date:
January 1, 2005 12:44
Subject:
RFC: Math::BigInt Calc vs. FastCalc
Message ID:
200501012145.04397@bloodgate.com
-----BEGIN PGP SIGNED MESSAGE-----

Moin,

in a recent discussion with Ed Allen Smith about FastCalc the topic of Calc 
vs. FastCalc came up. See:

	http://tinyurl.com/3sm6m

Basically, FastCalc is a faster version of Calc because it has some of the 
operations in XS instead in Perl.

The advantage of FastCalc over GMP, Pari etc al is that it is never slower - 
GMP et al. keep the numbers internally in base 2 (instead of base 10) and 
thus some operations can be slower (e.g. everything that looks at a number in 
base ten, like rounding, length() etc)ยด, as well as operations with very 
small numbers).

However, FastCalc shares about 80% of the code with Calc, which now creates a 
maintenance nightmare for me - each update of Calc also needs an copy&paste 
update in FastCalc. And each bugfix that changes the testsuite in BigInt 
needs also a new FastCalc release. Ugh.

OTOH, I wouldn't want to replace Calc in BigInt with FastCalc, because a 
pure-perl implementation is still better on platforms where the XS cannot be 
compiled (lack of compiler f.i.). Having the ability to just copy BigInt.pm 
and Calc.pm over and getting them instantly to work is sometimes incredible 
usefull.

After a long thinking I got an idea:

I could fuse FastCalc into Calc, so that the latter tries to load FastCalc, 
and if it failes, just continues normally. If it works, the FastCalc routines 
replace the Calc ones.

Advantages:

* no changes in BigInt.pm at all
* minimal changes in Calc to allow optional loading of FastCalc
* I need no longer to maintain a sepate package, this frees my time for other 
important work (and also avoids that a borken FastCalc package floats around 
because I forgot to test it with the latest BigInt)
* people get (slightly) faster Bigint math by default - Allen reports a factor 
two for his cases - this varies greatly depending on which operations you 
use, of course. However, every bit helps. Right now most people don't know 
that they can install an extra library to get faster math, or they lack the 
tools for this (like under some OS).

Disadvantages:

* slight bloat for the core - FastCalc.xs must be included (it is, however, 
small compared to BigInt.pm and Calc.pm - 11 Kb vs. 130 + 60 Kbyte!)
* testsuite should cover both paths. That will increase the tests quite a bit 
if not done intelligently. Right now you only incure both testsuites if you 
install FastCalc on top of a normal Perl.

Regardless of whether this is done, the actual overhead in BigInt itself must 
still be addressed. A seperate mail from me will deal with ideas on how to do 
this.

Tell me what you think of this.

Best wishes,

Tels

- -- 
 Signed on Sat Jan  1 21:27:39 2005 with key 0x93B84C15.
 Visit my photo gallery at http://bloodgate.com/photos/
 PGP key on http://bloodgate.com/tels.asc or per email.

 "Five exclamation marks, the sure sign of an insane mind." -- Terry
 Pratchett

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iQEVAwUBQdcLzncLPEOTuEwVAQFKOAf6ArpisrdBU4BCblZ64HFBiikWvma8zLR7
pksJWqbtPNI/x6/UE8foQx9vP8rd5ib7ERGSEZwSYD1QDPFxJ9hgQj4nwU5F6qkR
ZE43pBhW2QC4ARj3nUIHl2kVzfEv1YmoOZzgMwEWQoDIw94QfOOhEQlMFTSHgP3A
b6BGDKf5//2aZ7JZKu8/G1OeiqMsqJbbdNH4kUQlHa0uTb7QnyJ6wErwFRacsP1X
PNkcv7aKFW6KZfiio1u2sKk72JTxYuLc4SnEvUxwJ4/L42zFRhQGroP/RMohskkg
f0v4+2Kxq9vHoc09QSfcKHXjYdJOjsc+xIsrzUcsKp5uLbbxqFhXkA==
=cr/e
-----END PGP SIGNATURE-----

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About