Skip to content

Instantly share code, notes, and snippets.

@sanuj
Last active August 29, 2015 14:15
Show Gist options
  • Save sanuj/1099abec85e90b11eb0d to your computer and use it in GitHub Desktop.
Save sanuj/1099abec85e90b11eb0d to your computer and use it in GitHub Desktop.
Shogun Dot Comparison - Native vs Eigen3
#include <hayai.hpp>
#include <shogun/mathematics/linalg/linalg.h>
using namespace shogun;
using namespace std;
const index_t size=1000;
SGVector<float64_t> a(size), b(size);
void initialize() {
for(int32_t i=0; i<size; i++) {
a[i] = i;
b[i] = i+1;
}
}
void dotNative() {
ASSERT (linalg::dot<linalg::Backend::NATIVE>(a, b) == 333333000);
}
void dotEigen3() {
ASSERT (linalg::dot<linalg::Backend::EIGEN3>(a, b) == 333333000);
}
BENCHMARK(DotComparison, Native, 100, 100)
{
dotNative();
}
BENCHMARK(DotComparison, Eigen3, 100, 100)
{
dotEigen3();
}
int main()
{
initialize();
hayai::ConsoleOutputter consoleOutputter;
hayai::Benchmarker::AddOutputter(consoleOutputter);
hayai::Benchmarker::RunAllTests();
return 0;
}
[==========] Running 2 benchmarks.
[ RUN ] DotComparison.Native (100 runs, 100 iterations per run)
[ DONE ] DotComparison.Native (15.386000 ms)
[ RUNS ] Average time: 153.860 us
Fastest: 140.000 us (-13.860 us / -9.008 %)
Slowest: 277.000 us (+123.140 us / +80.034 %)
Average performance: 6499.41505 runs/s
Best performance: 7142.85714 runs/s (+643.44209 runs/s / +9.90000 %)
Worst performance: 3610.10830 runs/s (-2889.30675 runs/s / -44.45487 %)
[ITERATIONS] Average time: 1.539 us
Fastest: 1.400 us (-0.139 us / -9.008 %)
Slowest: 2.770 us (+1.231 us / +80.034 %)
Average performance: 649941.50526 iterations/s
Best performance: 714285.71429 iterations/s (+64344.20902 iterations/s / +9.90000 %)
Worst performance: 361010.83032 iterations/s (-288930.67494 iterations/s / -44.45487 %)
[ RUN ] DotComparison.Eigen3 (100 runs, 100 iterations per run)
[ DONE ] DotComparison.Eigen3 (15.861000 ms)
[ RUNS ] Average time: 158.610 us
Fastest: 100.000 us (-58.610 us / -36.952 %)
Slowest: 855.000 us (+696.390 us / +439.058 %)
Average performance: 6304.77271 runs/s
Best performance: 10000.00000 runs/s (+3695.22729 runs/s / +58.61000 %)
Worst performance: 1169.59064 runs/s (-5135.18207 runs/s / -81.44912 %)
[ITERATIONS] Average time: 1.586 us
Fastest: 1.000 us (-0.586 us / -36.952 %)
Slowest: 8.550 us (+6.964 us / +439.058 %)
Average performance: 630477.27129 iterations/s
Best performance: 1000000.00000 iterations/s (+369522.72871 iterations/s / +58.61000 %)
Worst performance: 116959.06433 iterations/s (-513518.20697 iterations/s / -81.44912 %)
[==========] Ran 2 benchmarks.
@karlnapf
Copy link

eigen is slower?

@sanuj
Copy link
Author

sanuj commented Mar 24, 2015

That happened because I had missed to add -o while compiling it with g++ to enable optimizations of eigen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment