Commit Graph

3 Commits

Author SHA1 Message Date
Julien Fischer
49c4dff4bd Add more integer to string benchmarks.
benchmarks/progs/integer_to_string/uint32_conversion.m:
benchmarks/progs/integer_to_string/uint64_conversion.m:
     As above.
2021-12-06 00:42:53 +11:00
Julien Fischer
b6d888a06e Add a benchmark for uint64 to string conversion.
benchmarks/progs/integer_to_string/uint64_conversion.m:
    As above.
2021-11-21 02:49:33 +11:00
Julien Fischer
cd540da1f2 Speed up uint32 to string conversion in C grades.
In C grades, uint32_to_string/1 is currently implemented by doing the
following:

 1. Calling sprintf() to write the string into a buffer on the stack.
 2. Calling strlen() on the buffer to determine the actual number of digits.
 3. Allocate the appropriate amount of space on the heap.
 4. Copying the string from the buffer on to the heap.

The benchmark included in this diff contains a number of alternative
implementations, all of which avoid much of the above overhead.
All of these implementations work by computing the required number of digits,
allocating space on the heap and then writing the digits into the string
backwards.

library/string.m:
    Replace uint32_to_string with a faster implementation.
    (This is alternative 1 in the benchmark program below.)

tests/hard_coded/Mmakefile:
tests/hard_coded/uint32_to_string.{m,exp}:
    A test of uint32 to string.

benchmarks/progs/integer_to_string/uint32_conversion.m:
    A program for benchmarking various uint32 to string conversion
    implementations.
2021-10-27 22:28:01 +11:00