decimal threading cost?

R

Robin Becker

Does using the decimal module incur a penalty because it imports threading or do
I have to actually start a thread?
 
M

Mark Dickinson

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.
 
R

Robin Becker

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.

I guess I was more worried that the import might start the per thread
instruction count check even though I'm in a single thread process.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top