-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
93 lines (81 loc) · 2.73 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Simple test of tiny-crc
#include <cstdio>
#include <string>
#include <time.h>
#include "crc.h"
int main(int argc, char **argv)
{
using namespace tinycrc;
// Do Not change the values below!!!
const uint32_t answer32 = (0x839A0189);
const uint64_t answer64 = (0xFE0B022DEF83C224);
const std::string str = "When you invoke GCC, it normally does preprocessing, compilation, assembly and linking.";
uint32_t c32 = 0;
uint64_t c64 = 0;
time_t t = clock();
#ifndef USE_BOOST_LIB
c32 = crc32(str.data(), str.size());
printf("CRC32: hex 0x%08X dec %u\n", c32, c32);
printf("Invoke 10,000,000 times: ");
fflush(stdout);
for (int i = 0; i < 10000000; ++i) {
if ((c32 = crc32(str.data(), str.size())) != answer32) {
printf("Error: 0x%08X\n", c32);
break;
}
}
printf("%.2f seconds\n\n", (clock() - t)/(double)CLOCKS_PER_SEC);
t = clock();
c64 = crc64(str.data(), str.size());
printf("CRC64: hex 0x%16lX dec %zu\n", c64, c64);
printf("Invoke 10,000,000 times: ");
fflush(stdout);
for (int i = 0; i < 10000000; ++i) {
if ((c64 = crc64(str.data(), str.size())) != answer64) {
printf("Error: 0x%16lX\n", c64);
break;
}
}
printf("%.2f seconds\n\n", (clock() - t)/(double)CLOCKS_PER_SEC);
#endif
#ifdef USE_BOOST_LIB
const uint32_t answer32C = (0xFDB2E7B8);
t = clock();
c32 = boost_crc32(str.data(), str.size());
printf("CRC32-boost: hex 0x%08X dec %u\n", c32, c32);
printf("Invoke 10,000,000 times: ");
fflush(stdout);
for (int i = 0; i < 10000000; ++i) {
if ((c32 = boost_crc32(str.data(), str.size())) != answer32) {
printf("Error: 0x%08X\n", c32);
break;
}
}
printf("%.2f seconds\n\n", (clock() - t)/(double)CLOCKS_PER_SEC);
t = clock();
c32 = boost_crc32c(str.data(), str.size());
printf("CRC32-C-boost: hex 0x%08X dec %u\n", c32, c32);
printf("Invoke 10,000,000 times: ");
fflush(stdout);
for (int i = 0; i < 10000000; ++i) {
if ((c32 = boost_crc32c(str.data(), str.size())) != answer32C) {
printf("Error: 0x%08X\n", c32);
break;
}
}
printf("%.2f seconds\n\n", (clock() - t)/(double)CLOCKS_PER_SEC);
t = clock();
c64 = boost_crc64(str.data(), str.size());
printf("CRC64-boost: hex 0x%16lX dec %zu\n", c64, c64);
printf("Invoke 10,000,000 times: ");
fflush(stdout);
for (int i = 0; i < 10000000; ++i) {
if ((c64 = boost_crc64(str.data(), str.size())) != answer64) {
printf("Error: 0x%16lX\n", c64);
break;
}
}
printf("%.2f seconds\n\n", (clock() - t)/(double)CLOCKS_PER_SEC);
#endif
return 0;
}