Re:The unknown features of Python's `operator` module
by ViViDboarder on Sunday August 08, 2021 @12:28PM
(#28107898)
But if you’re doing that, why not just import the identical function?
[ Parent
| on HN ]
Re:The unknown features of Python's `operator` module
by sharikous on Sunday August 08, 2021 @12:41PM
(#28108017)
One major point of OP was that the functions defined in operators are faster. Grandparent comment argued that there is a measurement error that invalidates this point, since properly defined lambdas (or defs) are just as fast.
Of course the point regarding the simplicity of importing a function instead of defining it still stands.
I personally wouldn't mind defining those functions as they are very immediate. So from the article I would take only the part about the more exotic "operator".
Re:The unknown features of Python's `operator` module
by klyrs on Sunday August 08, 2021 @07:00PM
(#28110986)
The timings are certainly closer, but the built-in function imported from operator is still faster than the user-defined function. Not a big deal if you're doing simple stuff, but if this code is in a hot loop that 30% can make a measurable difference.