source: tests/CRC64Test.cxx @ ccf520e

Revision ccf520e, 1.9 KB checked in by Hal Finkel <hfinkel@…>, 10 years ago (diff)

Initial Commit

  • Property mode set to 100644
RevLine 
[ccf520e]1//                    Author: Hal Finkel
2
3#define _XOPEN_SOURCE 600
4
5#include <CRC64.h>
6
7#include <ctime>
8#include <vector>
9#include <iostream>
10
11using namespace std;
12int main(int argc, char *argv[]) {
13  int ntests = 10;
14  if (argc > 1) ntests = atoi(argv[1]);
15
16  int seed = 5;
17  if (argc > 2) seed = atoi(argv[2]);
18
19  int max_test_length = 2097152;
20  if (argc > 3) max_test_length = atoi(argv[3]);
21
22  cout << "Running " << ntests << " tests with seed " << seed << endl;
23
24  srand48(seed);
25
26#ifdef __bgp__
27#define THE_CLOCK CLOCK_REALTIME
28#else
29#define THE_CLOCK CLOCK_THREAD_CPUTIME_ID
30#endif
31
32  double tot_time = 0, tot_bytes = 0;
33
34  int ntest = 0;
35  while (++ntest <= ntests) {
36    cout << ntest << " ";
37
38    size_t test_length = (size_t) (max_test_length*(drand48()+1));
39    cout << test_length << " ";
40
41    vector<unsigned char> buffer(test_length);
42
43    for (size_t i = 0; i < test_length; ++i) {
44      buffer[i] = (unsigned char) (255*drand48());
45    }
46
47    timespec b_start, b_end;
48    clock_gettime(THE_CLOCK, &b_start);
49
50    uint64_t cs = crc64_omp(&buffer[0], test_length);
51
52    clock_gettime(THE_CLOCK, &b_end);
53    double b_time = (b_end.tv_sec - b_start.tv_sec);
54    b_time += 1e-9*(b_end.tv_nsec - b_start.tv_nsec);
55
56    tot_time += b_time;
57    tot_bytes += test_length;
58
59    // Copy the buffer and append the check bytes.
60    size_t tlend = 8;
61    buffer.resize(test_length + tlend, 0);
62    crc64_invert(cs, &buffer[test_length]);
63
64    string pass("pass"), fail("fail");
65    uint64_t csc = crc64(&buffer[0], test_length+tlend);
66    cout << ((csc == (uint64_t) -1) ? pass : fail) << " ";
67
68    size_t div_pt = (size_t) (test_length*drand48());
69    uint64_t cs1 = crc64(&buffer[0], div_pt);
70    uint64_t cs2 = crc64(&buffer[div_pt], test_length - div_pt);
71    csc = crc64_combine(cs1, cs2, test_length - div_pt);
72    cout << ((csc == cs) ? pass : fail);
73
74    cout << endl;
75  }
76
77  cout << (tot_bytes/(1024*1024))/tot_time << " MB/s" << endl;
78
79  return 0;
80}
81
Note: See TracBrowser for help on using the repository browser.