decimal threading cost?

Mark Dickinson dickinsm at gmail.com
Fri Jan 22 06:50:58 EST 2010


On Jan 22, 11:11 am, Robin Becker <ro... at reportlab.com> wrote:
> Does using the decimal module incur a penalty because it imports threading or do
> I have to actually start a thread?

There is at least one threading-related performance penalty that
doesn't involve the user actually starting a thread: any arithmetic
operation without an explicitly specified context (e.g., as invoked by
one of the standard arithmetic operators) has to make a call to
threading.local() to look up the current (thread-local) context.

I don't know offhand whether this penalty is significant for the
Python version of decimal, though it definitely *is* significant for
decimal-in-C rewrite that's in the works:  it would be interesting to
do some timings against a thread-unaware version of decimal.py.

--
Mark



More information about the Python-list mailing list