optimize piSwap and c++11 improvments
This commit is contained in:
201
main.cpp
201
main.cpp
@@ -110,27 +110,196 @@ private:
|
||||
|
||||
};
|
||||
*/
|
||||
struct A {
|
||||
double arr[1000];
|
||||
};
|
||||
|
||||
|
||||
//PIKbdListener kbd(0, 0, false);
|
||||
|
||||
void swap(int & x, int & y) {int t = x; x = y; y = t;}
|
||||
void swap2(int & x, int & y) {int t(std::move(x)); x = y; y = t;}
|
||||
void swap(size_t & x, size_t & y) {size_t t = x; x = y; y = t;}
|
||||
void swap2(size_t & x, size_t & y) {size_t t{std::move(x)}; x = y; y = t;}
|
||||
void swap(double & x, double & y) {double t = x; x = y; y = t;}
|
||||
void swap2(double & x, double & y) {double t(std::move(x)); x = std::move(y); y = std::move(t);}
|
||||
void swap(float & x, float & y) {float t = x; x = y; y = t;}
|
||||
void swap2(float & x, float & y) {float t(std::move(x)); x = std::move(y); y = std::move(t);}
|
||||
void swap(PIString & x, PIString & y) {PIString t = x; x = y; y = t;}
|
||||
void swap2(PIString & x, PIString & y) {PIString t(std::move(x)); x = std::move(y); y = std::move(t);}
|
||||
void swap(std::string & x, std::string & y) {std::string t = x; x = y; y = t;}
|
||||
void swap2(std::string & x, std::string & y) {std::string t{std::move(x)}; x = std::move(y); y = std::move(t);}
|
||||
void swap(A & x, A & y) {A t = x; x = y; y = t;}
|
||||
void swap2(A & x, A & y) {A t{std::move(x)}; x = std::move(y); y = std::move(t);}
|
||||
void swap(PIObject & x, PIObject & y) {A t = x; x = y; y = t;}
|
||||
//void swap2(PIObject & x, PIObject & y) {A t(std::move(x)); x = std::move(y); y = std::move(t);}
|
||||
|
||||
#include "pigpio.h"
|
||||
int main(int argc, char * argv[]) {
|
||||
PIObject * o = PIIODevice::createFromFullPath("ser://COM1");
|
||||
piCout << o;
|
||||
piCout << o->cast<PIIODevice>();
|
||||
piCout << o->cast<PISerial>();
|
||||
piCout << o->scopeList();
|
||||
piCout << "\n\n";
|
||||
PIMap<uint, PIObject::__MetaData> & m(PIObject::__meta_data());
|
||||
for (auto it = m.constBegin(); it != m.constEnd(); ++it) {
|
||||
const PIObject::__MetaData & md(it.value());
|
||||
piCout << it.key() << md.scope_list << md.scope_id << ":";
|
||||
for (auto j = md.eh_func.constBegin(); j != md.eh_func.constEnd(); ++j) {
|
||||
piCout << " " << j.value().fullFormat();
|
||||
}
|
||||
piCout << "";
|
||||
}/**/
|
||||
PITimeMeasurer tm;
|
||||
int m = 100000;
|
||||
int a = 99, b = 77;
|
||||
piCout << "int";
|
||||
tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
swap(a,b);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
swap2(a,b);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
piSwapBinary(a,b);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
piSwap(a,b);
|
||||
}
|
||||
piCout << tm.elapsed_s();
|
||||
|
||||
piCout << "size_t";
|
||||
size_t ta = 99, tb = 77;
|
||||
tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
swap(ta,tb);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
swap2(ta,tb);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
piSwapBinary(ta,tb);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
piSwap(ta,tb);
|
||||
}
|
||||
piCout << tm.elapsed_s();
|
||||
|
||||
piCout << "ullong";
|
||||
ullong lla = 99, llb = 77;
|
||||
tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
swap(lla,llb);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
swap2(lla,llb);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
piSwapBinary(lla,llb);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
piSwap(lla,llb);
|
||||
}
|
||||
piCout << tm.elapsed_s();
|
||||
|
||||
piCout << "double";
|
||||
double da = 0.99,db = 77.77;
|
||||
tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
swap(da,db);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
swap2(da,db);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
piSwapBinary(da,db);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
piSwap(da,db);
|
||||
}
|
||||
piCout << tm.elapsed_s();
|
||||
|
||||
piCout << "float";
|
||||
float fa = 0.99,fb = 77.77;
|
||||
tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
swap(fa,fb);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
swap2(fa,fb);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
piSwapBinary(fa,fb);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
piSwap(fa,fb);
|
||||
}
|
||||
piCout << tm.elapsed_s();
|
||||
|
||||
piCout << "A";
|
||||
A aa,ab;
|
||||
tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
swap(aa,ab);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
swap2(aa,ab);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
piSwapBinary(aa,ab);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
piSwap(aa,ab);
|
||||
}
|
||||
piCout << tm.elapsed_s();
|
||||
|
||||
piCout << "std::string";
|
||||
std::string ia = "123456789012345678901vfsdvsd2345678",ib = "qwertyvsdfvvsdvfsuiopqwertyuikolsdfghjklsdfghjk";
|
||||
tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
swap(ia,ib);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
swap2(ia,ib);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
ia.swap(ib);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
piSwap(ia,ib);
|
||||
}
|
||||
piCout << tm.elapsed_s();
|
||||
|
||||
|
||||
PIString sa = "123456789012345678901vfsdvsd2345678",sb = "qwertyvsdfvvsdvfsuiopqwertyuikolsdfghjklsdfghjk";
|
||||
piCout << "PIString";
|
||||
tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
swap(sa,sb);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
swap2(sa, sb);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
sa.swap(sb);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
piSwapBinary(sa, sb);
|
||||
}
|
||||
piCout << tm.elapsed_s(); tm.reset();
|
||||
for (int i = 0; i < m; ++i) {
|
||||
piSwap(sa, sb);
|
||||
}
|
||||
piCout << tm.elapsed_s();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user