3 ms·
The difference is 20ns, and if that's enough for you to care about you've got much bigger worries (like "using python").
by bigbillheck 3y ago
The difference is 20ns, and if that's enough for you to care about you've got much bigger worries (like "using python").
- IshKebab 3y agoI agree. If you're benchmarking this then you're using the wrong language. But I hadn't considered the fact that `dict` can be overridden. That was interesting.
- frakt0x90 3y agoI guess I see this post as more about profiling, discovering unintuitive differences, and exploring python internals than offering 20ns optimizations. I personally appreciated it.
- sjwhevvvvvsj 3y ago(+20ns x # calls made) can be significant if you’re dealing with billions of executions though. If nothing else a search/replace for “dict()” to “{}” could yield an aggregate performance bump with basically zero refactoring cost. Also re Python in general: love it or hate it, it “won” as the language of ML. If you want to use ML libraries you’ll be in python.
- ayhanfuat 3y agoIf you are building billions of dicts, the bottleneck will not be how you initialize them as empty dicts for sure.
- sjwhevvvvvsj 3y agoDistributed systems can get very big.
- arsome 3y agoYeah I would be much more concerned about things which cause exponential time increases, like developers who brute force search lists instead of using dictionaries than how they declare their dictionaries unless I was at the point of profiling and the dict() constructor was somehow near the top of the list.
- queuebert 3y agoI have a book on the shelf called "High Performance Python". Seriously, though, if every Python program in the world was 0.1% faster, that would probably save a lot of energy.
- viraptor 3y agoYou have to compare that to the amount of energy spent while making it 0.1% faster. On average, I'm not sure we'd be saving any energy. The one bit that would get any remotely relevant gain would be offset by lots of tools where that improvement happens once a week. How many minutes / how much energy would it take you to setup a project, run a profiler, do the fix, run tests/CI, commit, release, etc. -vs- how much energy would that 0.1% change save over years?
- nomel 3y agoBring globals into local scope, never use '.' in tight loops, avoid function calls, etc [1], sure make ugly python code. But, wow, it really can make a difference. [1] https://wiki.python.org/moin/PythonSpeed/PerformanceTips https://wiki.python.org/moin/PythonSpeed/PerformanceTips
- physPop 3y agoI'm not sure how many of those are valid any more.