Skip to content

Commit 6b51fe6

Browse files
committed
[2024/11] remove num_digits() cache, turns out it's faster just to calculate it
1 parent ac8a16a commit 6b51fe6

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

2024/11/script.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
help="output cache info")
1111

1212

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

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

5049

5150
def print_cache_info():
52-
num_digits_cache = num_digits.cache_info()
5351
split_cache = split.cache_info()
54-
print(f"num_digits: {num_digits_cache.hits} hits, {num_digits_cache.misses} misses")
55-
print(f"split: {split_cache.hits} hits, {split_cache.misses} misses")
56-
num_digits.cache_clear()
52+
print(f"split: {split_cache.hits} hits, {split_cache.misses} misses"
53+
f" | {split_cache.hits / (split_cache.hits + split_cache.misses) * 100:.1f}% hit rate")
5754
split.cache_clear()
5855

5956

0 commit comments

Comments
 (0)