performance test of FastCRC lib, compare hardware CRC with Arduino software CRC (crc16.h) and table driven implementation
main.cpp
00001 // test FastCRC performance, hardware vs avr softcrc 00002 //FastCRC 00003 //Benchmark 00004 // 00005 //(c) Frank Boesing 2014 00006 00007 #include "mbed.h" 00008 #include "FastCRC.h" 00009 #include "crc16.h" 00010 00011 Timer tmr; 00012 #define micros tmr.read_us 00013 00014 #define BUFSIZE 16384 00015 00016 00017 FastCRC8 CRC8; 00018 FastCRC16 CRC16; 00019 FastCRC32 CRC32; 00020 00021 uint8_t buf[BUFSIZE] __attribute__((aligned(4))); 00022 00023 // validation 00024 void printva(char * name, uint32_t check, uint32_t val){ 00025 printf("%s",name); 00026 if (check == val) 00027 printf(" is ok"); 00028 else 00029 printf(" is NOT ok"); 00030 printf("\n"); 00031 } 00032 00033 void validate() { 00034 uint32_t crc; 00035 uint8_t buf[9] = {'1','2','3','4','5','6','7','8','9'}; 00036 00037 00038 printf("CRC Validation\n"); 00039 00040 crc = CRC8.smbus(buf, sizeof(buf)); 00041 printva("SMBUS", 0xf4, crc); 00042 00043 crc = CRC8.maxim(buf, sizeof(buf)); 00044 printva("Maxim", 0xa1, crc); 00045 00046 crc = CRC16.ccitt(buf, sizeof(buf)); 00047 printva("CCITT", 0x29b1, crc); 00048 00049 crc = CRC16.mcrf4xx(buf, sizeof(buf)); 00050 printva("MCRF4XX", 0x6f91, crc); 00051 00052 crc = CRC16.modbus(buf, sizeof(buf)); 00053 printva("MODBUS", 0x4b37, crc); 00054 00055 crc = CRC16.kermit(buf, sizeof(buf)); 00056 printva("KERMIT", 0x2189, crc); 00057 00058 crc = CRC16.xmodem(buf, sizeof(buf)); 00059 printva("XMODEM", 0x31c3, crc); 00060 00061 crc = CRC16.x25(buf, sizeof(buf)); 00062 printva("X.25", 0x906e, crc); 00063 00064 crc = CRC32.crc32(buf, sizeof(buf)); 00065 printva("CRC32", 0xcbf43926, crc); 00066 00067 crc = CRC32.cksum(buf, sizeof(buf)); 00068 printva("CKSUM", 0x765e7680, crc); 00069 } 00070 00071 00072 // Supporting functions for Software CRC 00073 00074 inline uint16_t softcrc(uint16_t seed, uint8_t *data, uint16_t datalen) { 00075 for (uint16_t i=0; i<datalen; i++) { 00076 seed = _crc16_update(seed, data[i]); 00077 } 00078 return seed; 00079 } 00080 00081 inline uint16_t softcrcIbutton(uint16_t seed, uint8_t *data, uint16_t datalen) { 00082 for (uint16_t i=0; i<datalen; i++) { 00083 seed = _crc_ibutton_update(seed, data[i]); 00084 } 00085 return seed; 00086 } 00087 00088 inline uint16_t softcrcCCIT(uint16_t seed, uint8_t *data, uint16_t datalen) { 00089 for (uint16_t i=0; i<datalen; i++) { 00090 seed = _crc_ccitt_update(seed, data[i]); 00091 } 00092 return seed; 00093 } 00094 00095 inline uint16_t softcrcXMODEM(uint16_t seed, uint8_t *data, uint16_t datalen) { 00096 for (uint16_t i=0; i<datalen; i++) { 00097 seed = _crc_xmodem_update(seed, data[i]); 00098 } 00099 return seed; 00100 } 00101 00102 00103 void printVals(char * name, uint32_t crc, uint32_t time) { 00104 printf("%s Value:0x%x, Time: %d us\n",name,crc,time); 00105 } 00106 00107 main() { 00108 uint32_t time; 00109 uint32_t crc; 00110 00111 tmr.start(); 00112 printf("\nSystemCoreClock %d %s %s\n",SystemCoreClock,__TIME__,__DATE__); 00113 validate(); 00114 printf("\nCRC Benchmark %d bytes\n",sizeof(buf)); 00115 00116 //Fill array with data 00117 for (int i=0; i<BUFSIZE; i++) { 00118 buf[i] = (i+1) & 0xff; 00119 } 00120 00121 00122 time = micros(); 00123 crc = CRC8.maxim(buf, BUFSIZE); 00124 time = micros() - time; 00125 printVals("Maxim (iButton) FastCRC:",crc,time); 00126 00127 time = micros(); 00128 crc = softcrcIbutton(0, buf, BUFSIZE); 00129 time = micros() - time; 00130 printVals("Maxim (iButton) builtin:",crc,time); 00131 00132 00133 time = micros(); 00134 crc = CRC16.modbus(buf, BUFSIZE); 00135 time = micros() - time; 00136 printVals("MODBUS FastCRC:",crc,time); 00137 00138 time = micros(); 00139 crc = softcrc(0xffff, buf, BUFSIZE); 00140 time = micros() - time; 00141 printVals("MODBUS builtin:",crc,time); 00142 00143 00144 time = micros(); 00145 crc = CRC16.xmodem(buf, BUFSIZE); 00146 time = micros() - time; 00147 printVals("XMODEM FastCRC:",crc,time); 00148 00149 time = micros(); 00150 crc = softcrcXMODEM(0, buf, BUFSIZE); 00151 time = micros() - time; 00152 printVals("XMODEM builtin:",crc,time); 00153 00154 time = micros(); 00155 crc = CRC16.mcrf4xx(buf,BUFSIZE); 00156 time = micros() - time; 00157 printVals("MCRF4XX FastCRC:",crc,time); 00158 00159 time = micros(); 00160 crc = softcrcCCIT(0xffff, buf, BUFSIZE); 00161 time = micros() - time; 00162 printVals("MCRF4XX builtin:",crc,time); 00163 00164 00165 time = micros(); 00166 crc = CRC16.kermit(buf, BUFSIZE); 00167 time = micros() - time; 00168 printVals("KERMIT FastCRC:",crc,time); 00169 00170 time = micros(); 00171 crc = CRC32.crc32(buf, BUFSIZE); 00172 time = micros() - time; 00173 printVals("Ethernet FastCRC:",crc,time); 00174 }
Generated on Wed Jul 13 2022 12:38:49 by 1.7.2