Skip to content

Commit

Permalink
[2024/11] remove num_digits() cache, turns out it's faster just to ca…
Browse files Browse the repository at this point in the history
…lculate it
  • Loading branch information
StarlitGhost committed Dec 11, 2024
1 parent ac8a16a commit 6b51fe6
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions 2024/11/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
help="output cache info")


@cache
def num_digits(value: int) -> int:
return int(math.log10(value)) + 1

Expand Down Expand Up @@ -49,11 +48,9 @@ def blink_n_times(stones: dict[int, int], n: int) -> dict[int, int]:


def print_cache_info():
num_digits_cache = num_digits.cache_info()
split_cache = split.cache_info()
print(f"num_digits: {num_digits_cache.hits} hits, {num_digits_cache.misses} misses")
print(f"split: {split_cache.hits} hits, {split_cache.misses} misses")
num_digits.cache_clear()
print(f"split: {split_cache.hits} hits, {split_cache.misses} misses"
f" | {split_cache.hits / (split_cache.hits + split_cache.misses) * 100:.1f}% hit rate")
split.cache_clear()


Expand Down

0 comments on commit 6b51fe6

Please sign in to comment.