Created
August 3, 2021 14:44
-
-
Save dongwooklee96/c600e36209813e098adc6a5755b01826 to your computer and use it in GitHub Desktop.
set vs dict
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import random | |
import pytest | |
nums = list(random.randint(1, 100) for _ in range(100)) | |
@pytest.mark.benchmark( | |
min_rounds=10000000, | |
timer=time.time, | |
disable_gc=True, | |
warmup=True | |
) | |
def test_use_dict(benchmark): | |
@benchmark | |
def func1(): | |
list(dict.fromkeys(nums)) | |
@pytest.mark.benchmark( | |
min_rounds=10000000, | |
timer=time.time, | |
disable_gc=True, | |
warmup=True | |
) | |
def test_use_set(benchmark): | |
@benchmark | |
def func2(): | |
list(set(nums)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment