add the bench file for the RandomSetter

This commit is contained in:
Gael Guennebaud 2008-10-21 00:05:45 +00:00
parent 3645d6c138
commit 9e02e42ff6
2 changed files with 117 additions and 4 deletions

View File

@ -90,12 +90,12 @@ class RandomSetter
inline RandomSetter(SparseMatrixType& target)
: mp_target(&target)
{
int outerPackets = target.outerSize() >> OuterPacketBits;
m_outerPackets = target.outerSize() >> OuterPacketBits;
if (target.outerSize()&OuterPacketMask)
outerPackets += 1;
m_hashmaps = new HashMapType[outerPackets];
m_outerPackets += 1;
m_hashmaps = new HashMapType[m_outerPackets];
KeyType ik = (1<<OuterPacketBits)*mp_target->innerSize()+1;
for (int k=0; k<outerPackets; ++k)
for (int k=0; k<m_outerPackets; ++k)
HashMapTraits<ScalarWrapper>::setInvalidKey(m_hashmaps[k],ik);
}
@ -115,11 +115,20 @@ class RandomSetter
return m_hashmaps[outerMajor][key].value;
}
int nonZeros() const
{
int nz = 0;
for (int k=0; k<m_outerPackets; ++k)
nz += m_hashmaps[k].size();
return nz;
}
protected:
HashMapType* m_hashmaps;
SparseMatrixType* mp_target;
int m_outerPackets;
};
#endif // EIGEN_RANDOMSETTER_H

View File

@ -0,0 +1,104 @@
#define NOGMM
#define NOMTL
#include <map>
#include <ext/hash_map>
#include <google/dense_hash_map>
#include <google/sparse_hash_map>
#ifndef SIZE
#define SIZE 10000
#endif
#ifndef DENSITY
#define DENSITY 0.01
#endif
#ifndef REPEAT
#define REPEAT 1
#endif
#include "BenchSparseUtil.h"
#ifndef MINDENSITY
#define MINDENSITY 0.0004
#endif
#ifndef NBTRIES
#define NBTRIES 10
#endif
#define BENCH(X) \
timer.reset(); \
for (int _j=0; _j<NBTRIES; ++_j) { \
timer.start(); \
for (int _k=0; _k<REPEAT; ++_k) { \
X \
} timer.stop(); }
int main(int argc, char *argv[])
{
int rows = SIZE;
int cols = SIZE;
float density = DENSITY;
EigenSparseMatrix sm1(rows,cols), sm2(rows,cols);
int n = rows*cols*density;
std::cout << "n = " << n << "\n";
int dummy;
BenchTimer t;
t.reset(); t.start();
for (int k=0; k<n; ++k)
dummy = ei_random<int>(0,rows-1) + ei_random<int>(0,cols-1);
t.stop();
double rtime = t.value();
std::cout << "rtime = " << rtime << " (" << dummy << ")\n\n";
const int Bits = 6;
for (;;)
{
{
RandomSetter<EigenSparseMatrix,StdMapTraits,Bits> set1(sm1);
t.reset(); t.start();
for (int k=0; k<n; ++k)
set1(ei_random<int>(0,rows-1),ei_random<int>(0,cols-1)) += 1;
t.stop();
std::cout << "std::map => \t" << t.value()-rtime
<< " nnz=" << set1.nonZeros() << "\n";getchar();
}
{
RandomSetter<EigenSparseMatrix,GnuHashMapTraits,Bits> set1(sm1);
t.reset(); t.start();
for (int k=0; k<n; ++k)
set1(ei_random<int>(0,rows-1),ei_random<int>(0,cols-1)) += 1;
t.stop();
std::cout << "gnu::hash_map => \t" << t.value()-rtime
<< " nnz=" << set1.nonZeros() << "\n";getchar();
}
{
RandomSetter<EigenSparseMatrix,GoogleDenseHashMapTraits,Bits> set1(sm1);
t.reset(); t.start();
for (int k=0; k<n; ++k)
set1(ei_random<int>(0,rows-1),ei_random<int>(0,cols-1)) += 1;
t.stop();
std::cout << "google::dense => \t" << t.value()-rtime
<< " nnz=" << set1.nonZeros() << "\n";getchar();
}
{
RandomSetter<EigenSparseMatrix,GoogleSparseHashMapTraits,Bits> set1(sm1);
t.reset(); t.start();
for (int k=0; k<n; ++k)
set1(ei_random<int>(0,rows-1),ei_random<int>(0,cols-1)) += 1;
t.stop();
std::cout << "google::sparse => \t" << t.value()-rtime
<< " nnz=" << set1.nonZeros() << "\n";getchar();
}
std::cout << "\n\n";
}
return 0;
}