source: tests/CRC64Test.cxx @ 96316ba

Revision 96316ba, 4.1 KB checked in by Hal Finkel <hfinkel@…>, 10 years ago (diff)

Add license provided by Argonne

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