6 #include <ext/hash_map>
7 #include <google/dense_hash_map>
8 #include <google/sparse_hash_map>
22 #include "BenchSparseUtil.h"
25 #define MINDENSITY 0.0004
34 for (int _j=0; _j<NBTRIES; ++_j) { \
36 for (int _k=0; _k<REPEAT; ++_k) { \
42 static double nentries
;
44 template<typename SetterType
>
45 void dostuff(const char* name
, EigenSparseMatrix
& sm1
)
47 int rows
= sm1
.rows();
48 int cols
= sm1
.cols();
51 SetterType
* set1
= new SetterType(sm1
);
53 for (int k
=0; k
<nentries
; ++k
)
54 (*set1
)(internal::random
<int>(0,rows
-1),internal::random
<int>(0,cols
-1)) += 1;
56 std::cout
<< "std::map => \t" << t
.value()-rtime
57 << " nnz=" << set1
->nonZeros() << std::flush
;
61 t
.reset(); t
.start(); delete set1
; t
.stop();
62 std::cout
<< " back: \t" << t
.value() << "\n";
65 int main(int argc
, char *argv
[])
69 float density
= DENSITY
;
71 EigenSparseMatrix
sm1(rows
,cols
), sm2(rows
,cols
);
74 nentries
= rows
*cols
*density
;
75 std::cout
<< "n = " << nentries
<< "\n";
80 for (int k
=0; k
<nentries
; ++k
)
81 dummy
= internal::random
<int>(0,rows
-1) + internal::random
<int>(0,cols
-1);
84 std::cout
<< "rtime = " << rtime
<< " (" << dummy
<< ")\n\n";
88 dostuff
<RandomSetter
<EigenSparseMatrix
,StdMapTraits
,Bits
> >("std::map ", sm1
);
89 dostuff
<RandomSetter
<EigenSparseMatrix
,GnuHashMapTraits
,Bits
> >("gnu::hash_map", sm1
);
90 dostuff
<RandomSetter
<EigenSparseMatrix
,GoogleDenseHashMapTraits
,Bits
> >("google::dense", sm1
);
91 dostuff
<RandomSetter
<EigenSparseMatrix
,GoogleSparseHashMapTraits
,Bits
> >("google::sparse", sm1
);
94 // RandomSetter<EigenSparseMatrix,GnuHashMapTraits,Bits> set1(sm1);
95 // t.reset(); t.start();
96 // for (int k=0; k<n; ++k)
97 // set1(internal::random<int>(0,rows-1),internal::random<int>(0,cols-1)) += 1;
99 // std::cout << "gnu::hash_map => \t" << t.value()-rtime
100 // << " nnz=" << set1.nonZeros() << "\n";getchar();
103 // RandomSetter<EigenSparseMatrix,GoogleDenseHashMapTraits,Bits> set1(sm1);
104 // t.reset(); t.start();
105 // for (int k=0; k<n; ++k)
106 // set1(internal::random<int>(0,rows-1),internal::random<int>(0,cols-1)) += 1;
108 // std::cout << "google::dense => \t" << t.value()-rtime
109 // << " nnz=" << set1.nonZeros() << "\n";getchar();
112 // RandomSetter<EigenSparseMatrix,GoogleSparseHashMapTraits,Bits> set1(sm1);
113 // t.reset(); t.start();
114 // for (int k=0; k<n; ++k)
115 // set1(internal::random<int>(0,rows-1),internal::random<int>(0,cols-1)) += 1;
117 // std::cout << "google::sparse => \t" << t.value()-rtime
118 // << " nnz=" << set1.nonZeros() << "\n";getchar();