Skip to content

Commit 753c337

Browse files
rijnbclaude
andcommitted
perf: A4 — single division per iteration in encodeBase31
Compute quotient once, derive remainder via subtraction so the loop has one division-class op per character rather than two. time ./unittest (best of 3, user): baseline = 114.13s after A4 = 114.35s delta = -0.19% cumulative (within noise floor) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1b01b82 commit 753c337

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

mapcodelib/mapcoder.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,9 +1096,11 @@ static void encodeBase31(char* result, int value, int nrchars) {
10961096
ASSERT(nrchars >= 0);
10971097
result[nrchars] = 0; // zero-terminate!
10981098
while (nrchars > 0) {
1099+
const int q = value / 31;
1100+
const int r = value - q * 31;
10991101
nrchars--;
1100-
result[nrchars] = ENCODE_CHARS[value % 31];
1101-
value /= 31;
1102+
result[nrchars] = ENCODE_CHARS[r];
1103+
value = q;
11021104
}
11031105
}
11041106

0 commit comments

Comments
 (0)