N (dimension) |
vec runtime [s] |
valarray runtime [s] |
---|---|---|
3 | 1.82 | 14.7 |
10 | 1.82 | 14.7 |
15 | 1.82 | 14.7 |
20 | 13.8 | 14.7 |
25 | 17.2 | 14.7 |
50 | 40.5 | 14.7 |
100 | 78.4 | 14.7 |
Last active
May 6, 2016 12:27
-
-
Save jgreitemann/a56524c547c2ceecb81f58cb572fe370 to your computer and use it in GitHub Desktop.
Benchmark of vec class vs. valarray
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <valarray> | |
using namespace std; | |
inline double norm_sq(const valarray<double>& v) { | |
return (v*v).sum(); | |
} | |
int main(int argc, char *argv[]) { | |
const size_t N = 3; | |
const size_t M = 100000000; | |
volatile double sum = 0.; | |
for (size_t m = 0; m < M; ++m) { | |
valarray<double> v(N, 1); | |
valarray<double> w(N, 1); | |
sum += norm_sq(v); | |
sum += norm_sq(w); | |
sum += norm_sq(v+w); | |
sum += norm_sq(v-w); | |
sum += (42. * v)[1]; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vec.hpp> | |
using namespace std; | |
using namespace Vec; | |
int main(int argc, char *argv[]) { | |
const size_t N = 3; | |
const size_t M = 100000000; | |
volatile double sum = 0.; | |
for (size_t m = 0; m < M; ++m) { | |
vec<N,double> v(1.); | |
vec<N,double> w(1.); | |
sum += v.norm_sq(); | |
sum += w.norm_sq(); | |
sum += (v+w).norm_sq(); | |
sum += (v-w).norm_sq(); | |
sum += (42. * v)[1]; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment