diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2025-11-27 15:35:05 +0100 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2025-11-27 15:35:05 +0100 |
| commit | 1ea5990be22994ad4d740f5d47da27780c6a1efc (patch) | |
| tree | 35794ef251209763a7af925220f163204c8324f4 /tests | |
| parent | 78d8059ebebda8b9bcd4959d804e1bab7d0254e7 (diff) | |
Speed up big.itoa
Extract 18 (64-bit) or 8 (32-bit) digits per big division.
This gives a 2.5x speedup for a 1024-bit bigint.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/core/math/big/test_core_math_big.odin | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/core/math/big/test_core_math_big.odin b/tests/core/math/big/test_core_math_big.odin index 321cd9418..a91c257ae 100644 --- a/tests/core/math/big/test_core_math_big.odin +++ b/tests/core/math/big/test_core_math_big.odin @@ -287,4 +287,31 @@ atoi :: proc(t: ^testing.T, i: ^big.Int, a: string, loc := #caller_location) -> err := big.atoi(i, a, 16) testing.expect(t, err == nil, loc=loc) return err == nil +} + +@(test) +test_itoa :: proc(t: ^testing.T) { + a := &big.Int{} + big.random(a, 2048) + defer big.destroy(a) + + for radix in 2..=64 { + if big.is_power_of_two(radix) { + // Powers of two are trivial, and are handled before `_itoa_raw_*` is called. + continue + } + + size, _ := big.radix_size(a, i8(radix), false) + buffer_old := make([]u8, size) + defer delete(buffer_old) + buffer_new := make([]u8, size) + defer delete(buffer_new) + + written_old, _ := big._itoa_raw_old (a, i8(radix), buffer_old, false) + written_new, _ := big._itoa_raw_full(a, i8(radix), buffer_new, false) + + str_old := string(buffer_old[:written_old]) + str_new := string(buffer_new[:written_new]) + testing.expect_value(t, str_new, str_old) + } }
\ No newline at end of file |