Skip to content

Instantly share code, notes, and snippets.

@lambday
Last active March 5, 2016 16:07
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/7cbd77eb0530ad41d9f5 to your computer and use it in GitHub Desktop.
Save lambday/7cbd77eb0530ad41d9f5 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 = 100;
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;
float64_t result = 0;
BENCHMARK(SGVector, linalg, 10, 100000)
{
result = linalg::dot(d.v1, d.v2);
}
BENCHMARK(SGVector, linalg_native, 10, 100000)
{
result = linalg::dot<linalg::Backend::NATIVE>(d.v1, d.v2);
}
BENCHMARK(SGVector, linalg_naked_ptr, 10, 100000)
{
result = linalg::implementation::dot<linalg::Backend::NATIVE,SGVector<float64_t>>::compute(d.v1.vector, d.v2.vector, d.size);
}
BENCHMARK(SGVector, eigen_map, 10, 100000)
{
Map<const VectorXd> map1(d.v1.vector, d.v1.vlen);
Map<const VectorXd> map2(d.v2.vector, d.v2.vlen);
result = map1.dot(map2);
}
BENCHMARK(SGVector, cmath, 10, 100000)
{
result = CMath::dot(d.v1.vector, d.v2.vector, d.size);
}
[==========] Running 5 benchmarks.
[ RUN ] SGVector.linalg (10 runs, 100000 iterations per run)
[ DONE ] SGVector.linalg (158.978000 ms)
[ RUNS ] Average time: 15897.800 us
Fastest: 15667.000 us (-230.800 us / -1.452 %)
Slowest: 16453.000 us (+555.200 us / +3.492 %)
Average performance: 62.90179 runs/s
Best performance: 63.82843 runs/s (+0.92664 runs/s / +1.47316 %)
Worst performance: 60.77919 runs/s (-2.12260 runs/s / -3.37446 %)
[ITERATIONS] Average time: 0.159 us
Fastest: 0.157 us (-0.002 us / -1.452 %)
Slowest: 0.165 us (+0.006 us / +3.492 %)
Average performance: 6290178.51527 iterations/s
Best performance: 6382842.91824 iterations/s (+92664.40297 iterations/s / +1.47316 %)
Worst performance: 6077918.92056 iterations/s (-212259.59470 iterations/s / -3.37446 %)
[ RUN ] SGVector.linalg_native (10 runs, 100000 iterations per run)
[ DONE ] SGVector.linalg_native (223.996000 ms)
[ RUNS ] Average time: 22399.600 us
Fastest: 21058.000 us (-1341.600 us / -5.989 %)
Slowest: 27436.000 us (+5036.400 us / +22.484 %)
Average performance: 44.64365 runs/s
Best performance: 47.48789 runs/s (+2.84424 runs/s / +6.37098 %)
Worst performance: 36.44846 runs/s (-8.19519 runs/s / -18.35690 %)
[ITERATIONS] Average time: 0.224 us
Fastest: 0.211 us (-0.013 us / -5.989 %)
Slowest: 0.274 us (+0.050 us / +22.484 %)
Average performance: 4464365.43510 iterations/s
Best performance: 4748789.05879 iterations/s (+284423.62369 iterations/s / +6.37098 %)
Worst performance: 3644846.18749 iterations/s (-819519.24761 iterations/s / -18.35690 %)
[ RUN ] SGVector.linalg_naked_ptr (10 runs, 100000 iterations per run)
[ DONE ] SGVector.linalg_naked_ptr (94.517000 ms)
[ RUNS ] Average time: 9451.700 us
Fastest: 9406.000 us (-45.700 us / -0.484 %)
Slowest: 9560.000 us (+108.300 us / +1.146 %)
Average performance: 105.80107 runs/s
Best performance: 106.31512 runs/s (+0.51405 runs/s / +0.48586 %)
Worst performance: 104.60251 runs/s (-1.19856 runs/s / -1.13285 %)
[ITERATIONS] Average time: 0.095 us
Fastest: 0.094 us (-0.000 us / -0.484 %)
Slowest: 0.096 us (+0.001 us / +1.146 %)
Average performance: 10580107.28229 iterations/s
Best performance: 10631511.80098 iterations/s (+51404.51869 iterations/s / +0.48586 %)
Worst performance: 10460251.04603 iterations/s (-119856.23626 iterations/s / -1.13285 %)
[ RUN ] SGVector.eigen_map (10 runs, 100000 iterations per run)
[ DONE ] SGVector.eigen_map (40.857000 ms)
[ RUNS ] Average time: 4085.700 us
Fastest: 3981.000 us (-104.700 us / -2.563 %)
Slowest: 4179.000 us (+93.300 us / +2.284 %)
Average performance: 244.75610 runs/s
Best performance: 251.19317 runs/s (+6.43707 runs/s / +2.62999 %)
Worst performance: 239.29170 runs/s (-5.46440 runs/s / -2.23259 %)
[ITERATIONS] Average time: 0.041 us
Fastest: 0.040 us (-0.001 us / -2.563 %)
Slowest: 0.042 us (+0.001 us / +2.284 %)
Average performance: 24475610.05458 iterations/s
Best performance: 25119316.75458 iterations/s (+643706.70000 iterations/s / +2.62999 %)
Worst performance: 23929169.65781 iterations/s (-546440.39677 iterations/s / -2.23259 %)
[ RUN ] SGVector.cmath (10 runs, 100000 iterations per run)
[ DONE ] SGVector.cmath (30.526000 ms)
[ RUNS ] Average time: 3052.600 us
Fastest: 2930.000 us (-122.600 us / -4.016 %)
Slowest: 3237.000 us (+184.400 us / +6.041 %)
Average performance: 327.58960 runs/s
Best performance: 341.29693 runs/s (+13.70733 runs/s / +4.18430 %)
Worst performance: 308.92802 runs/s (-18.66158 runs/s / -5.69663 %)
[ITERATIONS] Average time: 0.031 us
Fastest: 0.029 us (-0.001 us / -4.016 %)
Slowest: 0.032 us (+0.002 us / +6.041 %)
Average performance: 32758959.57544 iterations/s
Best performance: 34129692.83276 iterations/s (+1370733.25732 iterations/s / +4.18430 %)
Worst performance: 30892801.97714 iterations/s (-1866157.59830 iterations/s / -5.69663 %)
[==========] Ran 5 benchmarks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment