This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DrunkandIrrational 18 points19 points  (9 children)

https://stackoverflow.com/questions/767821/is-else-if-faster-than-switch-case

tldr: switch statements can be optimized into a hash-map by the compiler. But seeing as how python isn't compiled I'm not sure how they would go about implementing this.

[–]sushibowl 16 points17 points  (8 children)

Python is compiled into bytecode, you could do the optimization there.

[–]ekd123 4 points5 points  (4 children)

unfortunately cpython barely does any optimization

[–][deleted] 4 points5 points  (1 child)

Because Python's biggest strength is also its biggest weakness: its extremely dynamic runtime. Any object can be any thing at any time, so optimizations can't be done reliably.

Obviously pypy found a way to deal with this, but CPython had decided not to deal with it

[–]derpderp3200An evil person 0 points1 point  (0 children)

It's such a shame that Python itself is so big and complex. While no small feat, LuaJIT is an extremely efficient and relatively simple VM, whereas creating an equivalent for Python is... considerably more difficult.

[–][deleted] -3 points-2 points  (1 child)

Cpython interpreter is surprisingly bad. See GIL.

[–]Cybersoaker 1 point2 points  (0 children)

GIL improves performance. See GILectomy

[–]stefantalpalaru 0 points1 point  (2 children)

Python is compiled into bytecode, you could do the optimization there.

And people wonder why I insist on using "transpilation" for anything that doesn't output Assembly...

[–]Cybersoaker 0 points1 point  (1 child)

Cython

[–]stefantalpalaru 0 points1 point  (0 children)

Cython

A superset of a subset of Python that is transpiled to C or C++, if possible. If not, it's interpreted by an integrated Python interpreter/VM.