-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharma.cpp
165 lines (125 loc) · 3.57 KB
/
arma.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <blaze/Blaze.h>
#include <nt2/table.hpp>
#include <nt2/include/functions/size.hpp>
#include <nt2/include/functions/transpose.hpp>
#include <nt2/linalg/mtimes.hpp>
#include <stdlib.h>
#include <ctime>
#include <sys/time.h>
#include <eigen3/Eigen/Core>
#include <armadillo>
#include <vector>
#include <TooN/TooN.h>
static const size_t K = 9;
static const size_t L = 3;
static const size_t M = 1;
template<int K, int L> struct Arma
{
typedef arma::mat::fixed<K,L> type;
};
template<int K> struct Arma<K,1>
{
typedef arma::vec::fixed<K> type;
};
template<int K, int L> struct TOON
{
typedef TooN::Matrix<K,L> type;
};
template<int K> struct TOON<K,1>
{
typedef TooN::Vector<K> type;
};
template<int K, int L> struct BLAZE
{
typedef blaze::StaticMatrix<double,K,L> type;
};
template<int K> struct BLAZE<K,1>
{
typedef blaze::StaticVector<double,K> type;
};
typedef Arma<K,L>::type Arma93;
typedef Arma<K,M>::type Arma91;
typedef Arma<L,M>::type Arma33;
typedef Eigen::Matrix<double,K,L> Eigen93;
typedef Eigen::Matrix<double,K,M> Eigen91;
typedef Eigen::Matrix<double,L,M> Eigen33;
typedef TOON<K,L>::type TooN93;
typedef TOON<K,M>::type TooN91;
typedef TOON<L,M>::type TooN33;
typedef BLAZE<K,L>::type Blaze93;
typedef BLAZE<K,M>::type Blaze91;
typedef BLAZE<L,M>::type Blaze33;
typedef nt2::table<double, nt2::settings( nt2::of_size_<9,3>, nt2::C_index_) > NT293;
typedef nt2::table<double, nt2::settings( nt2::of_size_<9,1>, nt2::C_index_) > NT291;
typedef nt2::table<double, nt2::settings( nt2::of_size_<3,1>, nt2::C_index_) > NT233;
//typedef nt2::table<double,9,3> Nt293;
static inline double _now() {
size_t hi, lo;
__asm __volatile ("rdtsc" : "=a" (lo), "=d" (hi));
return double((long long)hi << 32 | lo);
}
static inline double now() {
struct timeval tp;
gettimeofday(&tp,NULL);
return double(tp.tv_sec) + double(tp.tv_usec)*1e-6;
}
int main()
{
size_t n = 1000000;
double t1,t2,t3,t4,t5;
{
std::vector<Arma93> v39(n);
std::vector<Arma91> r91(n);
std::vector<Arma33> v33(n);
t1 = now();
for(size_t i = 0 ; i < n ; ++i)
r91[i] = v39[i] * v33[i];
t1 = now() - t1;
std::cout << r91.back() << std::endl;
}
{
std::vector<Eigen93,Eigen::aligned_allocator<Eigen93>> v39(n);
std::vector<Eigen91,Eigen::aligned_allocator<Eigen91>> r91(n);
std::vector<Eigen33,Eigen::aligned_allocator<Eigen33>> v33(n);
t2 = now();
for(size_t i = 0 ; i < n ; ++i)
r91[i] = v39[i] * v33[i];
t2 = now() - t2;
std::cout << r91.back() << std::endl;
}
{
std::vector<TooN93> v39(n);
std::vector<TooN91> r91(n);
std::vector<TooN33> v33(n);
t3 = now();
for(size_t i = 0 ; i < n ; ++i)
r91[i] = v39[i] * v33[i];
t3 = now() - t3;
std::cout << r91.back() << std::endl;
}
{
std::vector<Blaze93> v39(n);
std::vector<Blaze91> r91(n);
std::vector<Blaze33> v33(n);
t4 = now();
for(size_t i = 0 ; i < n ; ++i)
r91[i] = v39[i] * v33[i];
t4 = now() - t4;
std::cout << r91.back() << std::endl;
}
{
std::vector<NT293> v39(n);
std::vector<NT291> r91(n);
std::vector<NT233> v33(n);
t5 = now();
for(size_t i = 0 ; i < n ; ++i)
r91[i] = nt2::multiplies(v39[i],v33[i]);
t5 = now() - t5;
std::cout << r91.back() << std::endl;
}
std::cout << " Arma : " << t1 << std::endl;
std::cout << " Eigen : " << t2 << std::endl;
std::cout << " TooN : " << t3 << std::endl;
std::cout << " Blaze : " << t4 << std::endl;
std::cout << " NT2 : " << t5 << std::endl;
}