Comment

Comment by klodolph

There are some weird performance optimizations in Python, e.g.,

    item = some_dict.get(key)
    if item is None:
        # key does not exist
Versus

    try:
        item = some_dict[key]
    except KeyError:
        # key does not exist
When I tested these (admittedly, a while ago), which one was faster depended on how often the key was missing. If “missing key” was an expected case, the first one was faster. If “missing key” was uncommon, the second was faster. It sounds like the fast path in the second case is getting faster, so this performance gap may be increasing.
parent klodolph 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton