Skip to content

Instantly share code, notes, and snippets.

@lambday
Created March 5, 2016 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lambday/938eaf0b0a7962769c46 to your computer and use it in GitHub Desktop.
Save lambday/938eaf0b0a7962769c46 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <shogun/lib/common.h>
#include <shogun/lib/SGVector.h>
#include <shogun/mathematics/Math.h>
#include <shogun/mathematics/linalg/linalg.h>
#include <hayai/hayai.hpp>
using namespace shogun;
using namespace Eigen;
struct data
{
const index_t size = 1000000;
SGVector<float64_t> v1;
SGVector<float64_t> v2;
data()
{
v1 = SGVector<float64_t>(size);
v2 = SGVector<float64_t>(size);
std::iota(v1.vector, v1.vector + v1.vlen, 1);
std::iota(v2.vector, v2.vector + v2.vlen, 1);
std::for_each(v1.vector, v1.vector + v1.vlen, [this](float64_t& v) { v /= size; });
std::for_each(v2.vector, v2.vector + v2.vlen, [this](float64_t& v) { v /= size; });
}
};
data d;
BENCHMARK(SGVector, linalg, 10, 1000)
{
linalg::dot(d.v1, d.v2);
}
BENCHMARK(SGVector, cmath, 10, 1000)
{
CMath::dot(d.v1.vector, d.v2.vector, d.size);
}
[==========] Running 2 benchmarks.
[ RUN ] SGVector.linalg (10 runs, 1000 iterations per run)
[ DONE ] SGVector.linalg (10616.001000 ms)
[ RUNS ] Average time: 1061600.100 us
Fastest: 1053427.000 us (-8173.100 us / -0.770 %)
Slowest: 1068386.000 us (+6785.900 us / +0.639 %)
Average performance: 0.94197 runs/s
Best performance: 0.94928 runs/s (+0.00731 runs/s / +0.77586 %)
Worst performance: 0.93599 runs/s (-0.00598 runs/s / -0.63515 %)
[ITERATIONS] Average time: 1061.600 us
Fastest: 1053.427 us (-8.173 us / -0.770 %)
Slowest: 1068.386 us (+6.786 us / +0.639 %)
Average performance: 941.97429 iterations/s
Best performance: 949.28267 iterations/s (+7.30838 iterations/s / +0.77586 %)
Worst performance: 935.99130 iterations/s (-5.98299 iterations/s / -0.63515 %)
[ RUN ] SGVector.cmath (10 runs, 1000 iterations per run)
[ DONE ] SGVector.cmath (10559.558000 ms)
[ RUNS ] Average time: 1055955.800 us
Fastest: 1046578.000 us (-9377.800 us / -0.888 %)
Slowest: 1064675.000 us (+8719.200 us / +0.826 %)
Average performance: 0.94701 runs/s
Best performance: 0.95549 runs/s (+0.00849 runs/s / +0.89604 %)
Worst performance: 0.93925 runs/s (-0.00776 runs/s / -0.81895 %)
[ITERATIONS] Average time: 1055.956 us
Fastest: 1046.578 us (-9.378 us / -0.888 %)
Slowest: 1064.675 us (+8.719 us / +0.826 %)
Average performance: 947.00934 iterations/s
Best performance: 955.49496 iterations/s (+8.48562 iterations/s / +0.89604 %)
Worst performance: 939.25376 iterations/s (-7.75557 iterations/s / -0.81895 %)
[==========] Ran 2 benchmarks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment