[Tutor] Standard Library Performance (3.4.1)
Alan Gauld
alan.gauld at btinternet.com
Fri Oct 24 13:03:41 CEST 2014
On 24/10/14 02:45, Adam Jensen wrote:
> I'm tinkering this evening and I've noticed that math.factorial() is
> much faster than my plain python implementations.
>
> Is this kind of performance difference typical of the standard library
> functions (compared to plain python user implementations)?
Yes, its often the case that the library functions are written in C and
compiled into libraries. That makes them much faster than your Python
code being executed within the Python interpreter.
In addition the library code has typically been fine tuned and optimised
over many releases so its about as fast as it can get.
(Your Python code could be optimised a bit but it would still
not be as fast as a C implementation.)
Not all library modules are C based however so it doesn't
always apply. But they are usually optimised and thoroughly
debugged so it is still worth using them rather than building
your own.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list