-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.cpp
More file actions
56 lines (42 loc) · 1.71 KB
/
benchmark.cpp
File metadata and controls
56 lines (42 loc) · 1.71 KB
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
//
// (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>
#include "sums.h"
/* 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};
float *A = (float *)malloc(sizeof(float) * MAX_PROBLEM_SIZE);
int n_problems = problem_sizes.size();
/* For each test size */
for (int64_t n : problem_sizes)
{
float t;
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
std::chrono::time_point<std::chrono::high_resolution_clock> start_time = std::chrono::high_resolution_clock::now();
// 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
std::chrono::time_point<std::chrono::high_resolution_clock> end_time = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time);
std::cout << " Elapsed time is : " << elapsed.count() << " ms" << std::endl;
printf(" Sum result = %lf \n",t);
} // end loop over problem sizes
}
// EOF