반응형
ubuntu에 boost library 설치하기
sudo apt install libboost-all-dev |
#include <iostream>
#include <chrono>
#include <cstdio>
#include <boost/crc.hpp>
using namespace std;
using boost::crc_32_type;
int main()
{
char testStr1[] = "12345678901234567890";
char testStr2[] = "12345678901234567891";
crc_32_type crc;
printf("crc size: %d\n", sizeof(unsigned int));
crc.process_bytes(testStr1, sizeof(testStr1));
printf("testStr1 crc: %08x\n", crc.checksum());
crc.process_bytes(testStr2, sizeof(testStr2));
printf("testStr2 crc: %08x\n", crc.checksum());
const size_t BYTE_4K = 4096;
auto testBuf = new char[BYTE_4K];
auto start = chrono::system_clock::now();
crc.process_bytes(testBuf, BYTE_4K);
auto result = crc.checksum();
auto end = chrono::system_clock::now() - start;
printf("testBuf crc: %08x\n", result);
printf("elapsed time: %ld us\n", chrono::duration_cast<chrono::microseconds>(end).count());
delete testBuf;
return 0;
}
실행하면..
crc size: 4 testStr1 crc: 81211fa4 testStr2 crc: 03beef0d testBuf crc: fa5e66f4 elapsed time: 12 us |
return value type은 unsigned int
4k buffer를 crc 계산하는데 내 pc에서 12 us 걸림 (amd 5600x)
반응형
'프로그래밍 > C & C++' 카테고리의 다른 글
fifo cache의 변형 (0) | 2022.02.01 |
---|---|
ubuntu에 google test (gtest) 설치 후 간단히 test (0) | 2022.02.01 |
ifstream, ofstream을 이용한 file 입출력 (0) | 2022.01.25 |
intel tbb::concurrent_queue를 multi level queue로 이용해보기 (0) | 2022.01.09 |
댓글