5 ms·
its also a level of indirection... It's sad but functions often slow performance down. but this depends on the language.
by nmz 4y ago
its also a level of indirection... It's sad but functions often slow performance down. but this depends on the language.
- marginalia_nu 4y agoCan't be many languages where that matters in 2022. Auto-inlining of short functions was a thing in the 1990s.
- extasia 4y agoThis may be true for compiled langs. In interpreted langs this is not the case. Function calls in Python for example are notoriously expensive.
- nmz 4y agoBeat me to it. Yes, I ran a quick benchmark[0] and not running a function always wins. now, one may argue that you are running a call, but if the interpreter was smart it would convert the small function calls to just a noops. [0]: https://github.com/Nomarian/crapbenchmarks/tree/main/call https://github.com/Nomarian/crapbenchmarks/tree/main/call Summary 'Perl/nofunc' ran 1.63 ± 0.30 times faster than 'Perl/func' 1.73 ± 0.34 times faster than 'Lua/nofunc' 2.11 ± 0.55 times faster than 'Lua/func' 9.37 ± 1.62 times faster than 'Python/nofunc' 12.18 ± 1.90 times faster than 'TCL/nofunc' 16.02 ± 2.58 times faster than 'TCL/func' 18.64 ± 3.02 times faster than 'Python/func'
- dTal 4y agoIf you're hand-wringing about the performance impact of function calls, Python is probably the wrong choice anyway.
- deleted 4y ago[deleted]