dtolnay / itoa

Fast function for printing integer primitives to a decimal string
Apache License 2.0
306 stars 37 forks source link

Write u128 using only two divisions #12

Closed dtolnay closed 7 years ago

dtolnay commented 7 years ago

@henninglive this one is a little faster than your implementation from #10. Basically it decomposes N into (N / 10^38 % 10) and (N / 10^19 % 10^19) and (N % 10^19).


Unoptimized

test bench_fmt::bench_u128_max  ... bench:       2,532 ns/iter (+/- 219)

PR #10

test bench_itoa::bench_u128_max ... bench:       1,171 ns/iter (+/- 30)

This one

test bench_itoa::bench_u128_max ... bench:         198 ns/iter (+/- 8)
henninglive commented 7 years ago

Wow, that’s fast. This is probably worth submitting as patch to std.

henninglive commented 7 years ago

We sould alos look into what happens with i64/u64 on x86, can we speed up too.

henninglive commented 7 years ago

The compiler-builtins copyright notice probably doesn’t apply anymore, you can probably remove it.

varkor commented 6 years ago

@dtolnay: are you planning to submit this upstream?

dtolnay commented 6 years ago

@varkor I am not planning to do it but it is being tracked in https://github.com/rust-lang/rust/issues/44583.