os-rust/library/core/src
Falk Hüffner d53c483502 Speed up integer log10.
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_zero to be viable, and might clog up the
cache.
2021-09-09 18:14:47 +02:00
..
alloc Consistent spelling of "adapter" in the standard library 2021-07-30 17:23:07 +02:00
array Auto merge of #88469 - patrick-gu:master, r=dtolnay 2021-09-05 01:56:25 +00:00
char Add a missing backtick 2021-09-03 17:11:57 -07:00
convert impl const From<num> for num 2021-08-07 19:03:08 +02:00
fmt fix clippy lints 2021-09-01 15:52:29 +03:00
future Fix may not to appropriate might not or must not 2021-07-29 01:15:20 -04:00
hash Rollup merge of #88031 - ibraheemdev:build-hasher-object-safe, r=m-ou-se 2021-08-18 19:54:57 +02:00
iter Stabilize Iterator::intersperse() 2021-08-31 14:50:18 -07:00
macros Make Arguments constructors unsafe 2021-08-16 16:28:16 +00:00
mem Fix typos “an”→“a” and a few different ones that appeared in the same search 2021-08-22 18:15:49 +02:00
num Speed up integer log10. 2021-09-09 18:14:47 +02:00
ops Remove the TryV2 alias 2021-08-21 15:09:03 -07:00
panic Fix unused sync::atomic import on targets without atomics 2021-07-31 17:27:29 -07:00
prelude Move asm! and global_asm! to core::arch 2021-07-18 18:30:58 -04:00
ptr remove redundant / misplaced sentence from docs 2021-09-01 20:52:30 -07:00
slice Add SAFETY comments to core::slice::sort::partition_in_blocks 2021-08-24 16:47:26 -03:00
str Auto merge of #83342 - Count-Count:win-console-incomplete-utf8, r=m-ou-se 2021-09-02 03:31:17 +00:00
stream Add core::stream::from_iter 2021-06-23 17:49:26 +02:00
sync Constified Default implementations 2021-08-17 07:15:54 +00:00
task Remove the TryV2 alias 2021-08-21 15:09:03 -07:00
unicode Use HTTPS links where possible 2021-06-23 16:26:46 -04:00
any.rs Added diagnostic items to structs and traits for Clippy 2021-07-15 23:57:02 +02:00
ascii.rs Replace all fmt.pad with debug_struct 2021-04-21 14:38:24 +02:00
bool.rs Fix accidentally deleted part 2021-09-03 17:13:42 -07:00
borrow.rs Fix borrow and deref 2021-03-03 11:23:29 +01:00
cell.rs Stabilize UnsafeCell::raw_get() 2021-08-31 14:44:13 -07:00
clone.rs Updates Clone docs for Copy comparison. 2021-06-10 11:28:26 -04:00
cmp.rs Add an example for deriving PartialOrd on enums 2021-08-20 22:24:22 -04:00
default.rs Constified Default implementations 2021-08-17 07:15:54 +00:00
ffi.rs Replace all fmt.pad with debug_struct 2021-04-21 14:38:24 +02:00
hint.rs Allow the use of the deprecated llvm_asm! in black_box 2021-08-15 13:14:32 +01:00
internal_macros.rs Remove unnecessary #[unstable] from internal macro. 2021-08-05 12:55:35 +02:00
intrinsics.rs Fix typos “an”→“a” and a few different ones that appeared in the same search 2021-08-22 18:15:49 +02:00
lazy.rs Capitalize safety comments 2020-09-08 22:26:44 -04:00
lib.rs Add carrying_add, borrowing_sub, widening_mul, carrying_mul methods to integers 2021-08-26 19:52:06 -04:00
marker.rs Constified Default implementations 2021-08-17 07:15:54 +00:00
option.rs use unwrap_unchecked where possible 2021-08-30 16:13:56 -04:00
panic.rs Move UnwindSafe, RefUnwindSafe, AssertUnwindSafe to core 2021-07-30 10:42:15 -07:00
panicking.rs Make Arguments constructors unsafe 2021-08-16 16:28:16 +00:00
pin.rs Fix may not to appropriate might not or must not 2021-07-29 01:15:20 -04:00
primitive.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
result.rs Remove the TryV2 alias 2021-08-21 15:09:03 -07:00
time.rs Adding examples to docs of std::time module 2021-08-29 23:59:35 -03:00
tuple.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
unit.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00