|
|
|
|
|
by driggs
205 days ago
|
|
Funny that Hack #1 compares list versus set value lookup, but the timer doesn't include the time to copy the list into a set. Hack #2 warns against unnecessary copying, and the time for copying the list is almost the same as the performance gain in Hack #1. In fact, creating a set takes longer than copying a list since it requires hash insertion, so it's actually much faster to do the opposite of what they suggest for #1 (in the case of a single lookup, for this test case). Here's the results with `big_set = set(big_list)` inside the timing block for the set case: List lookup: 0.013985s
Set lookup: 0.052468s
|
|