2 ms·
Alone the indentation makes the code clearer to read. Generally it seems to clean up the code quite a bit in comparison to the if-statements. I would like to h
by qwertox 5y ago
Alone the indentation makes the code clearer to read. Generally it seems to clean up the code quite a bit in comparison to the if-statements.
I would like to have seen some benchmarks for it, though, specially for things like the gaming loop, where, compared to the if-variant, the type of the event has to be checked for every case, since grouping is not possible.
This specific game loop is not adequate, since input events are rare, but if this were to be used with Scapy for example, it would really start to matter, like when iterating over raw socket events.
- benhoyt 5y agoSee my other comment with some quick benchmarks: https://news.ycombinator.com/item?id=28601862 https://news.ycombinator.com/item?id=28601862 Yeah, the match is slower than if-else in that case because they're not grouped. However, the PEP points out that faster implementations are possible -- it would not have to check the type each time if it already knows it can't match. I guess some of those optimizations are left for later.