Skip to content

Instantly share code, notes, and snippets.

@dongwooklee96
Created August 3, 2021 14:44
Show Gist options
  • Save dongwooklee96/c600e36209813e098adc6a5755b01826 to your computer and use it in GitHub Desktop.
Save dongwooklee96/c600e36209813e098adc6a5755b01826 to your computer and use it in GitHub Desktop.
set vs dict
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