RFC 1071 "internet checksum" computation.
This crate implements the "internet checksum" defined in RFC 1071 and updated in RFC 1141 and RFC 1624, which is used by many different protocols' packet formats. The checksum operates by computing the 1s complement of the 1s complement sum of successive 16-bit words of the input.
Benchmarks
[Checksum::add_bytes
]
The following microbenchmarks were performed on a 2018 Google Pixelbook. Each benchmark
constructs a [Checksum
] object, calls [Checksum::add_bytes
] with an input of the given
number of bytes, and then calls [Checksum::checksum
] to finalize. Average values were
calculated over 3 trials.
Bytes | Time | Rate |
---|---|---|
20 | 2,649 ns | 7.55 MB/s |
31 | 3,826 ns | 8.10 MB/s |
32 | 3,871 ns | 8.27 MB/s |
64 | 1,433 ns | 44.7 MB/s |
128 | 2,225 ns | 57.5 MB/s |
256 | 3,829 ns | 66.9 MB/s |
1023 | 13,802 ns | 74.1 MB/s |
1024 | 13,535 ns | 75.7 MB/s |
[Checksum::add_bytes_small
]
The following microbenchmarks were performed on a 2018 Google Pixelbook. Each benchmark
constructs a [Checksum
] object, calls [Checksum::add_bytes_small
] with an input of the
given number of bytes, and then calls [Checksum::checksum
] to finalize. Average values
were calculated over 3 trials.
Bytes | Time | Rate |
---|---|---|
20 | 2,639 ns | 7.57 MB/s |
31 | 3,806 ns | 8.15 MB/s |
[update
]
The following microbenchmarks were performed on a 2018 Google Pixelbook. Each benchmark
calls [update
] with an original 2 byte checksum, and byteslices of specified lengths
to be updated. Average values were calculated over 3 trials.
Bytes | Time | Rate |
---|---|---|
2 | 1,550 ns | 1.29 MB/s |
4 | 1,972 ns | 2.03 MB/s |
8 | 2,892 ns | 2.77 MB/s |