From f11468442c78d95adae9c447a7f6d74158ce2bf3 Mon Sep 17 00:00:00 2001 From: lambday Date: Sun, 7 Jul 2013 13:33:00 +0530 Subject: [PATCH] performance test of sparse-matrix vector product added --- benchmarks/sparse_test.cpp | 130 +++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 benchmarks/sparse_test.cpp diff --git a/benchmarks/sparse_test.cpp b/benchmarks/sparse_test.cpp new file mode 100644 index 00000000000..39e625103d1 --- /dev/null +++ b/benchmarks/sparse_test.cpp @@ -0,0 +1,130 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Written (W) 2013 Soumyajit De + */ + +#include + +#ifdef HAVE_EIGEN3 +#include +#include +#include +#include +#include +#include + +using namespace shogun; +using namespace Eigen; + +SGVector sg_m_apply(SGSparseMatrix m, SGVector v) +{ + SGVector r(v.vlen); + ASSERT(v.vlen==m.num_vectors); + for (index_t i=0; iset_loglevel(MSG_GCDEBUG); + + const index_t n=100; + const index_t times=5; + const index_t size=1000000; + SGVector v(size); + v.set_const(1.0); + Map map_v(v.vector, v.vlen); + clock_t start, end; + + SG_SPRINT("time\tshogun (s)\teigen3 (s)\n\n"); + for (index_t t=0; t sg_m(size, size); + typedef SGSparseVectorEntry Entry; + SGSparseVector *vec=SG_MALLOC(SGSparseVector, size); + + // for first row + Entry *first=SG_MALLOC(Entry, size); + // the digonal index for row #1 + first[0].feat_index=0; + first[0].entry=1.836593; + for (index_t i=1; i r(size); + + // sg starts + start=clock(); + for (index_t i=0; i(end-start)/CLOCKS_PER_SEC; + + Map map_r(r.vector, r.vlen); + float64_t sg_norm=map_r.norm(); + +//#endif // RUN_SHOGUN + +//#ifdef RUN_EIGEN + const SparseMatrix &eig_m=EigenSparseUtil::toEigenSparse(sg_m); + VectorXd eig_r(size); + + // eigen3 starts + start=clock(); + for (index_t i=0; i(end-start)/CLOCKS_PER_SEC; + + float64_t eig_norm=eig_r.norm(); +//#endif // RUN_EIGEN + + SG_SPRINT("%d\t%lf\t%lf\n", t, sg_time, eig_time); + ASSERT(sg_time>eig_time); + ASSERT(CMath::abs(sg_norm-eig_norm)<=CMath::MACHINE_EPSILON) + + SG_FREE(vec); + SG_FREE(rest); + } + + + exit_shogun(); + + return 0; +} +#endif // HAVE_EIGEN3