mrhooray / crc-rs

Rust implementation of CRC(16, 32, 64) with support of various standards
Apache License 2.0
187 stars 49 forks source link

Assert in slice16 hot loop to avoid bounds checks. #95

Open khrs opened 1 year ago

khrs commented 1 year ago

Little help for compiler to eliminate bounds checks in hot loop. Biggest gain are in crc32/crc64/crc128

crc8/slice16            time:   [4.1465 µs 4.1499 µs 4.1542 µs]
                        thrpt:  [3.6731 GiB/s 3.6769 GiB/s 3.6799 GiB/s]
                 change:
                        time:   [-1.3003% -1.0348% -0.8107%] (p = 0.00 < 0.05)
                        thrpt:  [+0.8174% +1.0457% +1.3174%]
                        Change within noise threshold.
Found 4 outliers among 100 measurements (4.00%)
  2 (2.00%) high mild
  2 (2.00%) high severe

crc16/slice16           time:   [4.1916 µs 4.1950 µs 4.1989 µs]
                        thrpt:  [3.6340 GiB/s 3.6374 GiB/s 3.6404 GiB/s]
                 change:
                        time:   [-6.0076% -5.1733% -4.3995%] (p = 0.00 < 0.05)
                        thrpt:  [+4.6020% +5.4555% +6.3915%]
                        Performance has improved.
Found 8 outliers among 100 measurements (8.00%)
  4 (4.00%) high mild
  4 (4.00%) high severe

crc32/slice16           time:   [4.6525 µs 4.6926 µs 4.7364 µs]
                        thrpt:  [3.2216 GiB/s 3.2516 GiB/s 3.2797 GiB/s]
                 change:
                        time:   [-5.9927% -5.6196% -5.2235%] (p = 0.00 < 0.05)
                        thrpt:  [+5.5114% +5.9542% +6.3747%]
                        Performance has improved.
Found 11 outliers among 100 measurements (11.00%)
  2 (2.00%) high mild
  9 (9.00%) high severe

crc64/slice16           time:   [5.3718 µs 5.3793 µs 5.3888 µs]
                        thrpt:  [2.8316 GiB/s 2.8366 GiB/s 2.8405 GiB/s]
                 change:
                        time:   [-13.005% -12.813% -12.565%] (p = 0.00 < 0.05)
                        thrpt:  [+14.371% +14.696% +14.950%]
                        Performance has improved.
Found 20 outliers among 100 measurements (20.00%)
  4 (4.00%) low severe
  4 (4.00%) high mild
  12 (12.00%) high severe

crc82/slice16           time:   [15.866 µs 15.886 µs 15.911 µs]
                        thrpt:  [982.02 MiB/s 983.56 MiB/s 984.80 MiB/s]
                 change:
                        time:   [-9.7310% -9.2953% -8.9176%] (p = 0.00 < 0.05)
                        thrpt:  [+9.7907% +10.248% +10.780%]
                        Performance has improved.
Found 12 outliers among 100 measurements (12.00%)
  1 (1.00%) high mild
  11 (11.00%) high severe
akhilles commented 1 year ago

This bumps MSRV, which I'm still considering (mainly for const generics). Maybe split the asserts into a separate PR so that the other changes can be merged?

khrs commented 1 year ago

Move "off-by-one" fix to #97

akhilles commented 1 year ago

See https://github.com/mrhooray/crc-rs/issues/96.