2 ms·
Does python document anything about performance? I assume my array sort won't be n^3, but how do we draw the line on what to assume and what not to assume?
by Dylan16807 6y ago
Does python document anything about performance?
I assume my array sort won't be n^3, but how do we draw the line on what to assume and what not to assume?
- jshprentz 6y agoPython uses Timsort[1]. They provide benchmarks and details at [2]. [1] https://en.wikipedia.org/wiki/Timsort https://en.wikipedia.org/wiki/Timsort [2] https://svn.python.org/projects/python/trunk/Objects/listsort.txt https://svn.python.org/projects/python/trunk/Objects/listsor...
- Dylan16807 6y agoThey also give details about the string implementation. I mean a guarantee that it meets some baseline efficiency that you can depend on across time and different implementations. Does that exist?
- rovr138 6y agoIf you're implementing it on python, check `dis.dis()` If builtin, then you'll need to check the code for cpython or whatever you're using.
- dmurray 6y agoThe closest thing Python has to a specification is the Language Reference. It shies well away from performance details and aims to describe "syntax and core semantics" while acknowledging that some parts of what it specifies may just be implementation details of CPython [0]. To draw the line on what you can assume re performance, you need a combination of background knowledge, folk wisdom and common sense. (You could say "or read the code" but that could change in the next minor version: you still need common sense to know if that's likely). This is unlike, e.g. C++ where there is a specification and standards-compliant compilers must implement certain functions with the specified runtime complexity. [0] https://docs.python.org/3/reference/introduction.html#alternate-implementations https://docs.python.org/3/reference/introduction.html#altern...
- Wicher 6y agoThere's https://wiki.python.org/moin/TimeComplexity https://wiki.python.org/moin/TimeComplexity but that's not official documentation.