Use a recursive algorithm based on repeatedly squaring the base for both to_base_ten and from_base_ten. The from_base_ten speedup is not as huge as I hoped, because Python’s divmod is pathetically slow, but it at least it’s slow C code rather than slow Python code.
Use a recursive algorithm based on repeatedly squaring the base for both
to_base_ten
andfrom_base_ten
. Thefrom_base_ten
speedup is not as huge as I hoped, because Python’s divmod is pathetically slow, but it at least it’s slow C code rather than slow Python code.Here are some benchmarks: