-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbenchmark.cpp
54 lines (39 loc) · 1.35 KB
/
benchmark.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
//
// (C) 2022-2023, E. Wes Bethel
// benchmark-* harness for running different versions of the sum study
// over different problem sizes
//
// usage: no command line arguments
// set problem sizes, block sizes in the code below
#include <algorithm>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <random>
#include <vector>
#include <string.h>
extern void setup(int64_t N, uint64_t A[]);
extern int64_t sum(int64_t N, uint64_t A[]);
/* The benchmarking program */
int main(int argc, char** argv)
{
std::cout << std::fixed << std::setprecision(2);
#define MAX_PROBLEM_SIZE 1 << 28 // 256M
std::vector<int64_t> problem_sizes{ MAX_PROBLEM_SIZE >> 5, MAX_PROBLEM_SIZE >> 4, MAX_PROBLEM_SIZE >> 3, MAX_PROBLEM_SIZE >> 2, MAX_PROBLEM_SIZE >> 1, MAX_PROBLEM_SIZE};
std::vector<uint64_t> A(MAX_PROBLEM_SIZE);
int64_t t;
int n_problems = problem_sizes.size();
/* For each test size */
for (int64_t n : problem_sizes)
{
printf("Working on problem size N=%lld \n", n);
// invoke user code to set up the problem
setup(n, &A[0]);
// insert your timer code here
// invoke method to perform the sum
t = sum(n, &A[0]);
// insert your end timer code here, and print out elapsed time for this problem size
printf(" Sum result = %lld \n",t);
} // end loop over problem sizes
}
// EOF