High-performance `fast-powi` crate
⚓ Rust 📅 2026-04-14 👤 surdeus 👁️ 3Following Fast powi function topic, I made a fast-powi crate. I only implemented 8-bit exponents; i.e, i8 and u8. I don't know of any practical use of exponents greater than 127. This allowed me to hard-code all the shortest "addition-chains" (or multiplication-chains in this case) for all u8 exponents. I decided to implement the num crate numerical types. It is about 10X faster than the standard library powi for floats on my computer. It is about 20% faster than most ints, bigints, and ratios. It is about 50% faster for complex ratio types.
Here is a summary of the benchmarks from my laptop.
f64_fast time: [765.08 ns 772.03 ns 778.96 ns]
f64_std time: [8.1878 µs 8.2823 µs 8.3878 µs]
bigint_fast time: [70.852 µs 71.336 µs 71.814 µs]
bigint_num time: [89.324 µs 89.779 µs 90.293 µs]
big_ratio_fast time: [303.19 µs 304.39 µs 305.70 µs]
big_ratio_num time: [355.01 µs 357.22 µs 359.59 µs]
u64_fast time: [105.52 ns 107.19 ns 108.99 ns]
u64_num time: [210.32 ns 213.48 ns 218.01 ns]
big_complex_ratio_fast time: [23.048 ms 23.522 ms 24.193 ms]
big_complex_ratio_num time: [32.578 ms 32.965 ms 33.449 ms]
You can find the benchmark code here
I probably should have ask for a review before publishing on crate.io, but I got "go fever" to publish my first crate. I would appreciate any input.
4 posts - 3 participants
🏷️ Rust_feed