sparse_randomsetter.cpp
Go to the documentation of this file.
1 
2 #define NOGMM
3 #define NOMTL
4 #define EIGEN_GOOGLEHASH_SUPPORT 1
5 
6 #include <map>
7 #include <ext/hash_map>
8 #include <google/dense_hash_map>
9 #include <google/sparse_hash_map>
10 
11 #ifndef SIZE
12 #define SIZE 10000
13 #endif
14 
15 #ifndef DENSITY
16 #define DENSITY 0.01
17 #endif
18 
19 #ifndef REPEAT
20 #define REPEAT 1
21 #endif
22 
23 #include "BenchSparseUtil.h"
24 
25 #ifndef MINDENSITY
26 #define MINDENSITY 0.0004
27 #endif
28 
29 #ifndef NBTRIES
30 #define NBTRIES 10
31 #endif
32 
33 #define BENCH(X) \
34  timer.reset(); \
35  for (int _j=0; _j<NBTRIES; ++_j) { \
36  timer.start(); \
37  for (int _k=0; _k<REPEAT; ++_k) { \
38  X \
39  } timer.stop(); }
40 
41 
42 static double rtime;
43 static double nentries;
44 
45 template<typename SetterType>
46 void dostuff(const char* name, EigenSparseMatrix& sm1)
47 {
48  int rows = sm1.rows();
49  int cols = sm1.cols();
50  sm1.setZero();
51  BenchTimer t;
52  SetterType* set1 = new SetterType(sm1);
53  t.reset(); t.start();
54  for (int k=0; k<nentries; ++k)
55  (*set1)(internal::random<int>(0,rows-1),internal::random<int>(0,cols-1)) += 1;
56  t.stop();
57  std::cout << "std::map => \t" << t.value()-rtime
58  << " nnz=" << set1->nonZeros() << std::flush;
59 
60  // getchar();
61 
62  t.reset(); t.start(); delete set1; t.stop();
63  std::cout << " back: \t" << t.value() << "\n";
64 }
65 
66 int main(int argc, char *argv[])
67 {
68  int rows = SIZE;
69  int cols = SIZE;
70  float density = DENSITY;
71 
72  EigenSparseMatrix sm1(rows,cols), sm2(rows,cols);
73 
74 
76  std::cout << "n = " << nentries << "\n";
77  int dummy;
78  BenchTimer t;
79 
80  t.reset(); t.start();
81  for (int k=0; k<nentries; ++k)
82  dummy = internal::random<int>(0,rows-1) + internal::random<int>(0,cols-1);
83  t.stop();
84  rtime = t.value();
85  std::cout << "rtime = " << rtime << " (" << dummy << ")\n\n";
86  const int Bits = 6;
87  for (;;)
88  {
89  dostuff<RandomSetter<EigenSparseMatrix,StdMapTraits,Bits> >("std::map ", sm1);
90  dostuff<RandomSetter<EigenSparseMatrix,GnuHashMapTraits,Bits> >("gnu::hash_map", sm1);
91  dostuff<RandomSetter<EigenSparseMatrix,GoogleDenseHashMapTraits,Bits> >("google::dense", sm1);
92  dostuff<RandomSetter<EigenSparseMatrix,GoogleSparseHashMapTraits,Bits> >("google::sparse", sm1);
93 
94 // {
95 // RandomSetter<EigenSparseMatrix,GnuHashMapTraits,Bits> set1(sm1);
96 // t.reset(); t.start();
97 // for (int k=0; k<n; ++k)
98 // set1(internal::random<int>(0,rows-1),internal::random<int>(0,cols-1)) += 1;
99 // t.stop();
100 // std::cout << "gnu::hash_map => \t" << t.value()-rtime
101 // << " nnz=" << set1.nonZeros() << "\n";getchar();
102 // }
103 // {
104 // RandomSetter<EigenSparseMatrix,GoogleDenseHashMapTraits,Bits> set1(sm1);
105 // t.reset(); t.start();
106 // for (int k=0; k<n; ++k)
107 // set1(internal::random<int>(0,rows-1),internal::random<int>(0,cols-1)) += 1;
108 // t.stop();
109 // std::cout << "google::dense => \t" << t.value()-rtime
110 // << " nnz=" << set1.nonZeros() << "\n";getchar();
111 // }
112 // {
113 // RandomSetter<EigenSparseMatrix,GoogleSparseHashMapTraits,Bits> set1(sm1);
114 // t.reset(); t.start();
115 // for (int k=0; k<n; ++k)
116 // set1(internal::random<int>(0,rows-1),internal::random<int>(0,cols-1)) += 1;
117 // t.stop();
118 // std::cout << "google::sparse => \t" << t.value()-rtime
119 // << " nnz=" << set1.nonZeros() << "\n";getchar();
120 // }
121  std::cout << "\n\n";
122  }
123 
124  return 0;
125 }
126 
Eigen::SparseMatrix::cols
Index cols() const
Definition: SparseMatrix.h:140
rtime
static double rtime
Definition: sparse_randomsetter.cpp:42
name
Annotation for function names.
Definition: attr.h:51
Eigen::SparseMatrix< Scalar >
main
int main(int argc, char *argv[])
Definition: sparse_randomsetter.cpp:66
SIZE
#define SIZE
Definition: sparse_randomsetter.cpp:12
nentries
static double nentries
Definition: sparse_randomsetter.cpp:43
DENSITY
#define DENSITY
Definition: sparse_randomsetter.cpp:16
dostuff
void dostuff(const char *name, EigenSparseMatrix &sm1)
Definition: sparse_randomsetter.cpp:46
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
pybind_wrapper_test_script.dummy
dummy
Definition: pybind_wrapper_test_script.py:42
Eigen::BenchTimer
Definition: BenchTimer.h:59
density
Definition: testGaussianConditional.cpp:127
Eigen::SparseMatrix::setZero
void setZero()
Definition: SparseMatrix.h:253
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
Eigen::SparseMatrix::rows
Index rows() const
Definition: SparseMatrix.h:138
align_3::t
Point2 t(10, 10)
BenchSparseUtil.h


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:04:24