Skip to content

Commit 51cbf06

Browse files
committed
Add comments in benchmark script
Signed-off-by: Jialin Ouyang <[email protected]>
1 parent 99ab0a2 commit 51cbf06

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

benchmarks/benchmark_bookkeep.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ def update_one_by_one(
2525
) -> None:
2626
for i in range(len(update_values)):
2727
if update_tags[i]:
28+
# Access a single value from numpy array
2829
start_idx = num_tokens_no_spec_np[i]
2930
end_idx = start_idx + update_values[i]
31+
# Update a single value to 2 numpy arrays
3032
num_tokens_no_spec_np[i] = end_idx
3133
num_tokens_np[i] = end_idx
3234

@@ -37,6 +39,7 @@ def update_by_batch(
3739
update_tags: list[bool],
3840
update_values: list[int],
3941
) -> None:
42+
# Convert numpy array to list once before for loop
4043
num_tokens_no_spec = num_tokens_no_spec_np.tolist()
4144
num_tokens_indices_to_update: list[int] = []
4245
num_tokens_values_to_update: list[int] = []
@@ -46,6 +49,7 @@ def update_by_batch(
4649
end_idx = start_idx + update_values[i]
4750
num_tokens_indices_to_update.append(i)
4851
num_tokens_values_to_update.append(end_idx)
52+
# Batch update numpy arrays after for loop
4953
if num_tokens_indices_to_update:
5054
num_tokens_no_spec_np[num_tokens_indices_to_update] = (
5155
num_tokens_values_to_update

0 commit comments

Comments
 (0)