Skip to content

Instantly share code, notes, and snippets.

@Jokeren
Created May 27, 2020 20:58
Show Gist options
  • Save Jokeren/50e33a538379808ebce0fdfd27c16fb1 to your computer and use it in GitHub Desktop.
Save Jokeren/50e33a538379808ebce0fdfd27c16fb1 to your computer and use it in GitHub Desktop.
Test
#include <iostream>
#include <chrono>
void __attribute__ ((noinline)) init(int *arr, size_t length) {
for (auto i = 0; i < length; ++i) {
arr[i] = 1;
}
}
void __attribute__ ((noinline)) compute(int *vec1, int *vec2, int *vec3, size_t length) {
for (auto i = 0; i < length; ++i) {
vec3[i] += vec1[i] * vec2[i];
}
}
int main() {
size_t length = 1000000;
size_t times = 100;
int *vec1 = new int[length];
int *vec2 = new int[length];
int *vec3 = new int[length];
init(vec1, length);
init(vec2, length);
init(vec3, length);
auto start = std::chrono::system_clock::now();
for (size_t i = 0; i < times; ++i) {
compute(vec1, vec2, vec3, length);
}
auto end = std::chrono::system_clock::now();
std::chrono::duration<double> diff = end - start;
std::cout << "Time: " << diff.count() << std::endl;
delete [] vec1;
delete [] vec2;
delete [] vec3;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment