source: tests/CRC64Test.cxx @ b8df02e

Revision b8df02e, 3.8 KB checked in by Hal Finkel <hfinkel@…>, 9 years ago (diff)

Update to new open-source license

  • Property mode set to 100644
Line 
1// *****************************************************************************
2//                   Copyright (C) 2014, UChicago Argonne, LLC
3//                              All Rights Reserved
4//             High-Performance CRC64 Library (ANL-SF-14-095)
5//                    Hal Finkel, Argonne National Laboratory
6//
7//                              OPEN SOURCE LICENSE
8//
9// Under the terms of Contract No. DE-AC02-06CH11357 with UChicago Argonne, LLC,
10// the U.S. Government retains certain rights in this software.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are met:
14//
15// 1. Redistributions of source code must retain the above copyright notice, this
16//    list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright notice,
19//    this list of conditions and the following disclaimer in the documentation
20//    and/or other materials provided with the distribution.
21//
22// 3. Neither the names of UChicago Argonne, LLC or the Department of Energy nor
23//    the names of its contributors may be used to endorse or promote products
24//    derived from this software without specific prior written permission.
25// 
26// *****************************************************************************
27//                                  DISCLAIMER
28//
29// THE SOFTWARE IS SUPPLIED "AS IS" WITHOUT WARRANTY OF ANY KIND.
30//
31// NEITHER THE UNTED STATES GOVERNMENT, NOR THE UNITED STATES DEPARTMENT OF
32// ENERGY, NOR UCHICAGO ARGONNE, LLC, NOR ANY OF THEIR EMPLOYEES, MAKES ANY
33// WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY
34// FOR THE ACCURACY, COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, DATA,
35// APPARATUS, PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT
36// INFRINGE PRIVATELY OWNED RIGHTS.
37//
38// *****************************************************************************
39
40#define _XOPEN_SOURCE 600
41
42#include <CRC64.h>
43
44#include <ctime>
45#include <vector>
46#include <iostream>
47
48using namespace std;
49int main(int argc, char *argv[]) {
50  int ntests = 10;
51  if (argc > 1) ntests = atoi(argv[1]);
52
53  int seed = 5;
54  if (argc > 2) seed = atoi(argv[2]);
55
56  int max_test_length = 2097152;
57  if (argc > 3) max_test_length = atoi(argv[3]);
58
59  cout << "Running " << ntests << " tests with seed " << seed << endl;
60
61  srand48(seed);
62
63#ifdef __bgp__
64#define THE_CLOCK CLOCK_REALTIME
65#else
66#define THE_CLOCK CLOCK_THREAD_CPUTIME_ID
67#endif
68
69  double tot_time = 0, tot_bytes = 0;
70
71  int ntest = 0;
72  while (++ntest <= ntests) {
73    cout << ntest << " ";
74
75    size_t test_length = (size_t) (max_test_length*(drand48()+1));
76    cout << test_length << " ";
77
78    vector<unsigned char> buffer(test_length);
79
80    for (size_t i = 0; i < test_length; ++i) {
81      buffer[i] = (unsigned char) (255*drand48());
82    }
83
84    timespec b_start, b_end;
85    clock_gettime(THE_CLOCK, &b_start);
86
87    uint64_t cs = crc64_omp(&buffer[0], test_length);
88
89    clock_gettime(THE_CLOCK, &b_end);
90    double b_time = (b_end.tv_sec - b_start.tv_sec);
91    b_time += 1e-9*(b_end.tv_nsec - b_start.tv_nsec);
92
93    tot_time += b_time;
94    tot_bytes += test_length;
95
96    // Copy the buffer and append the check bytes.
97    size_t tlend = 8;
98    buffer.resize(test_length + tlend, 0);
99    crc64_invert(cs, &buffer[test_length]);
100
101    string pass("pass"), fail("fail");
102    uint64_t csc = crc64(&buffer[0], test_length+tlend);
103    cout << ((csc == (uint64_t) -1) ? pass : fail) << " ";
104
105    size_t div_pt = (size_t) (test_length*drand48());
106    uint64_t cs1 = crc64(&buffer[0], div_pt);
107    uint64_t cs2 = crc64(&buffer[div_pt], test_length - div_pt);
108    csc = crc64_combine(cs1, cs2, test_length - div_pt);
109    cout << ((csc == cs) ? pass : fail);
110
111    cout << endl;
112  }
113
114  cout << (tot_bytes/(1024*1024))/tot_time << " MB/s" << endl;
115
116  return 0;
117}
118
Note: See TracBrowser for help on using the repository browser.