[Patches] [ python-Patches-1053375 ] Decimal speed up

SourceForge.net noreply at sourceforge.net
Tue Oct 26 06:53:07 CEST 2004


Patches item #1053375, was opened at 2004-10-24 16:01
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1053375&group_id=5470

Category: Library (Lib)
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Facundo Batista (facundobatista)
>Assigned to: Facundo Batista (facundobatista)
Summary: Decimal speed up

Initial Comment:
Raymond:

Some minor modifications: max() instead of veryfing
which is greater and assigning it, and not passing prec
to _fixexponents() (not uses it).

Major change: Not use _WorkRep anymore! Changed
__add__, __mul__ and __divide__ to support it
(including the support functions _normalize() and
_adjust_coefficients). And of course, Decimal.__new__
does not support passing _WorkRep anymore, ;).

One change that may raise controversial: The syntax to
pass a tuple to __new__ now accepts also a number in
the second position. This is because in some places in
the code the result is just a number, and converting it
to a tuple in the code (and not in __new__) made
redundant some checks in __new__.

All the tests pass ok. The new code shows a 12% speed
up in test_decimal.py and 10% in the telco benchmark.

.   Facundo

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2004-10-25 23:53

Message:
Logged In: YES 
user_id=80475

I tend to think this should probably not be done. 

On the plus side, there is the simplification of code
(saving approx 80 lines and eliminating an entire class of
objects).  Also, there is the modest speed-up.

On the minus side, it is rather late to be making big
changes to the module.

More importantly, I'm concerned about inlining _WorkRep's
internals.  Nick's use of Python ints as a temporary
representation is currently confined to _WorkRep.  That
choice was not the right way to go in the long term.  While
it saves time for the Python implementation, a C version
would go back to the method of shuffling bcd digits directly
(giving better big O performance and eliminating an
intermodule code dependency). 

The elimination of prec in the _fixexponents call is okay. 
Also, the max() call is fine.

----------------------------------------------------------------------

Comment By: Facundo Batista (facundobatista)
Date: 2004-10-25 21:56

Message:
Logged In: YES 
user_id=752496

Oops, don't know what happened. Here's the file complete.

.    Facundo

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-10-24 19:15

Message:
Logged In: YES 
user_id=80475

It looks like the file did not attach.
Please submit a whole decimal.py instead of a diff.
Thx, Raymond

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1053375&group_id=5470


More information about the Patches mailing list