Arduino Library for Fletcher's checksum
This library provides a Fletcher checksum of a data array.
Fletcher's checksum is in general faster than CRC but possibly not as good in detecting errors. See https://en.wikipedia.org/wiki/Fletcher%27s_checksum for details.
Relates to https://github.com/RobTillaart/CRC
Use https://github.com/RobTillaart/printHelpers to print the Fletcher64().
Tested on Arduino UNO + ESP32 + SAMD (See PR #7).
These interfaces are very similar for Fletcher16, Fletcher32 and Fletcher64 class.
#include "Fletcher16.h"
The checksum from getFletcher() can be split into a high and a low part to be used to "feed" begin() again. See restart example.
The functions are straightforward, however one should define length in terms of the data type and optional pad it with zeros.
A string "abcdef" has length 2 for fletcher64() as it needs 2x4 bytes.
#include "Fletcher.h"
Since 0.1.8: Added parameters s1 and s2 to make the functions more versatile. Defaults are backwards compatible.
Not tested ESP32 (and many other platforms) yet. First numbers of .add(value) measured with test sketch shows the following timing.
Checksum | UNO 16 MHz | ESP32 240 MHz |
---|---|---|
Fletcher16 | 3.8 us | 0.22 us |
Fletcher32 | 5.6 us | 0.23 us |
Fletcher64 | 10.1 us | 0.26 us |
Average | 6.5 us | 0.24 us |
Not tested extensively, first numbers of .add(array, length) measured with Fletcher_performance.ino sketch shows the following timing.
Lorem Ipsum text = 868 bytes.
Version 0.1.3.
Checksum | UNO 16 MHz | ESP32 240 MHz | Notes |
---|---|---|---|
Fletcher16 | 1120 us | 62 us | first run slower ? |
Fletcher32 | 728 us | 33 us | |
Fletcher64 | 1952 us | 35 us | |
Average | 1267 us | 43 us | |
Avg / char | 1.46 us | 0.0495 us | 868 bytes |
Note 0.1.4 has improved the performance. See PR #7 for some numbers.
See examples.
If you appreciate my libraries, you can support the development and maintenance. Improve the quality of the libraries by providing issues and Pull Requests, or donate through PayPal or GitHub sponsors.
Thank you,