From ce1391a738f9dbdc26595f0aaa2763114ab121f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Gr=C4=99dowski?= Date: Thu, 17 Oct 2024 09:54:01 +0200 Subject: [PATCH] feat: make code in primes.py slow --- src/profiling/README.md | 3 ++- src/profiling/primes.py | 25 ++----------------------- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/src/profiling/README.md b/src/profiling/README.md index 9a9f36d..846f68b 100644 --- a/src/profiling/README.md +++ b/src/profiling/README.md @@ -3,9 +3,10 @@ ## Setup ```bash -python3 -m venv .venv +python3 -m venv .venv # You can also use conda or virtualenv, your choice .venv\Scripts\activate # Windows # source .venv/bin/activate # Linux/MacOS +# conda activate your-environment-name # Conda pip install pyinstrument snakeviz ``` diff --git a/src/profiling/primes.py b/src/profiling/primes.py index 85fe585..0705573 100644 --- a/src/profiling/primes.py +++ b/src/profiling/primes.py @@ -14,12 +14,7 @@ def _slow_sort(arr): return arr -def _fast_sort(arr): - return sorted(arr) - - def sort(*args, **kwargs): - return _fast_sort(*args, **kwargs) return _slow_sort(*args, **kwargs) @@ -33,17 +28,8 @@ def _slow_prime_check(n): return True -def _faster_prime_check(n): - if n < 2: - return False - for i in range(2, int(n**0.5) + 1): - if n % i == 0: - return False - return True - - def prime_check(*args, **kwargs): - return _faster_prime_check(*args, **kwargs) + return _slow_prime_check(*args, **kwargs) def _slow_make_unique(data): @@ -64,15 +50,8 @@ def _slow_save_items(results, file_name): f.write(str(item) + "\n") -def _fast_save_items(results, file_name): - with open(file_name, "a") as f: - for item in results: - f.write(str(item) + "\n") - - def save_items(*args, **kwargs): - return _fast_save_items(*args, **kwargs) - # return _slow_save_items(*args, **kwargs) + return _slow_save_items(*args, **kwargs) def process_data(data):