rust/library/core/tests/num
bors ffdf18d144 Auto merge of #88788 - falk-hueffner:speedup-int-log10-branchless, r=joshtriplett
Speedup int log10 branchless

This is achieved with a branchless bit-twiddling implementation of the case x < 100_000, and using this as building block.

Benchmark on an Intel i7-8700K (Coffee Lake):

```
name                                   old ns/iter  new ns/iter  diff ns/iter   diff %  speedup
num::int_log::u8_log10_predictable     165          169                     4    2.42%   x 0.98
num::int_log::u8_log10_random          438          423                   -15   -3.42%   x 1.04
num::int_log::u8_log10_random_small    438          423                   -15   -3.42%   x 1.04
num::int_log::u16_log10_predictable    633          417                  -216  -34.12%   x 1.52
num::int_log::u16_log10_random         908          471                  -437  -48.13%   x 1.93
num::int_log::u16_log10_random_small   945          471                  -474  -50.16%   x 2.01
num::int_log::u32_log10_predictable    1,496        1,340                -156  -10.43%   x 1.12
num::int_log::u32_log10_random         1,076        873                  -203  -18.87%   x 1.23
num::int_log::u32_log10_random_small   1,145        874                  -271  -23.67%   x 1.31
num::int_log::u64_log10_predictable    4,005        3,171                -834  -20.82%   x 1.26
num::int_log::u64_log10_random         1,247        1,021                -226  -18.12%   x 1.22
num::int_log::u64_log10_random_small   1,265        921                  -344  -27.19%   x 1.37
num::int_log::u128_log10_predictable   39,667       39,579                -88   -0.22%   x 1.00
num::int_log::u128_log10_random        6,456        6,696                 240    3.72%   x 0.96
num::int_log::u128_log10_random_small  4,108        3,903                -205   -4.99%   x 1.05
```

Benchmark on an M1 Mac Mini:

```
name                                   old ns/iter  new ns/iter  diff ns/iter   diff %  speedup
num::int_log::u8_log10_predictable     143          130                   -13   -9.09%   x 1.10
num::int_log::u8_log10_random          375          325                   -50  -13.33%   x 1.15
num::int_log::u8_log10_random_small    376          325                   -51  -13.56%   x 1.16
num::int_log::u16_log10_predictable    500          322                  -178  -35.60%   x 1.55
num::int_log::u16_log10_random         794          405                  -389  -48.99%   x 1.96
num::int_log::u16_log10_random_small   1,035        405                  -630  -60.87%   x 2.56
num::int_log::u32_log10_predictable    1,144        894                  -250  -21.85%   x 1.28
num::int_log::u32_log10_random         832          786                   -46   -5.53%   x 1.06
num::int_log::u32_log10_random_small   832          787                   -45   -5.41%   x 1.06
num::int_log::u64_log10_predictable    2,681        2,057                -624  -23.27%   x 1.30
num::int_log::u64_log10_random         1,015        806                  -209  -20.59%   x 1.26
num::int_log::u64_log10_random_small   1,004        795                  -209  -20.82%   x 1.26
num::int_log::u128_log10_predictable   56,825       56,526               -299   -0.53%   x 1.01
num::int_log::u128_log10_random        9,056        8,861                -195   -2.15%   x 1.02
num::int_log::u128_log10_random_small  1,528        1,527                  -1   -0.07%   x 1.00
```

The 128 bit case remains ridiculously slow because llvm fails to optimize division by a constant 128-bit value to multiplications. This could be worked around but it seems preferable to fix this in llvm.

From u32 up, table lookup (like suggested [here](https://github.com/rust-lang/rust/issues/70887#issuecomment-881099813)) is still faster, but requires a hardware `leading_zeros` to be viable, and might clog up the cache.
2021-10-12 03:18:54 +00:00
..
dec2flt Changed dec2flt to use the Eisel-Lemire algorithm. 2021-07-17 00:30:34 -05:00
flt2dec Move flt2dec::{Formatted, Part} to dedicated module 2021-06-06 02:54:51 +01:00
bignum.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
const_from.rs Add test for int to float 2021-08-07 19:03:34 +02:00
i8.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
i16.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
i32.rs Minor refactoring 2020-09-05 17:07:53 +05:30
i64.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
i128.rs Add u128 and i128 integer tests 2020-11-14 20:27:08 +01:00
ieee754.rs Add IEEE754 tests 2021-03-22 17:02:06 -07:00
int_log.rs Speed up integer log10. 2021-09-09 18:14:47 +02:00
int_macros.rs Temporarily rename int_roundings functions to avoid conflicts 2021-09-22 13:56:01 -07:00
mod.rs Add tests 2021-08-07 19:03:33 +02:00
nan.rs Update tests to remove old numeric constants 2020-11-29 00:55:55 -05:00
ops.rs Adds tests to ensure some base op traits exist. 2021-01-13 23:14:00 -05:00
u8.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
u16.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
u32.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
u64.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
u128.rs Add u128 and i128 integer tests 2020-11-14 20:27:08 +01:00
uint_macros.rs Temporarily rename int_roundings functions to avoid conflicts 2021-09-22 13:56:01 -07:00
wrapping.rs Avoid ident concatenation in macro. 2021-01-13 23:13:55 -05:00