From 7763e7c0f3ea8cac5473a22ffcf53d048a1f301c Mon Sep 17 00:00:00 2001 From: Trey Fitzgerald Date: Wed, 13 May 2026 11:44:11 -0500 Subject: [PATCH 1/3] Indiv Comments --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 44e0723..f344a15 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Python Performance Lab: Sharpening Your Instincts +# Trey Perfomance Test A PyCon US 2026 hands-on tutorial. You optimize intentionally slow Python code across three rounds plus a team challenge, measuring every change with From f55950f67bcfb7da4b5bc66f82ecee5e6f06b1e1 Mon Sep 17 00:00:00 2001 From: TreyFitzgerald Date: Wed, 13 May 2026 12:00:19 -0500 Subject: [PATCH 2/3] What i did --- rounds/1_histogram/solution.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rounds/1_histogram/solution.py b/rounds/1_histogram/solution.py index dffbee5..2329311 100644 --- a/rounds/1_histogram/solution.py +++ b/rounds/1_histogram/solution.py @@ -8,7 +8,7 @@ def compute_histogram(path: str) -> dict[bytes, int]: """Frequency of every 2-byte bigram in the file at ``path``.""" - # TODO: remove this delegation and write your own implementation here. + # more TODO: remove this delegation and write your own implementation here. from .baseline import compute_histogram as _baseline return _baseline(path) From 76fb0a1a64f80842ba7a2542a78d5a28174b2eac Mon Sep 17 00:00:00 2001 From: TreyFitzgerald Date: Wed, 13 May 2026 12:17:04 -0500 Subject: [PATCH 3/3] Used Numpy --- rounds/1_histogram/solution.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/rounds/1_histogram/solution.py b/rounds/1_histogram/solution.py index 2329311..0b71e61 100644 --- a/rounds/1_histogram/solution.py +++ b/rounds/1_histogram/solution.py @@ -6,9 +6,25 @@ """ +import numpy as np + def compute_histogram(path: str) -> dict[bytes, int]: """Frequency of every 2-byte bigram in the file at ``path``.""" - # more TODO: remove this delegation and write your own implementation here. - from .baseline import compute_histogram as _baseline + data = np.fromfile(path, dtype=np.uint8) + + if len(data) < 2: + return {} + + bigrams = (data[:-1].astype(np.uint16) << 8) | data[1:] + counts = np.bincount(bigrams, minlength=65536) + + result = {} + nonzero_indices = np.nonzero(counts)[0] + + for idx in nonzero_indices: + byte1 = (idx >> 8) & 0xFF + byte2 = idx & 0xFF + result[bytes([byte1, byte2])] = int(counts[idx]) + + return result - return _baseline(path)