pimap tests
This commit is contained in:
322
main.cpp
322
main.cpp
@@ -1,235 +1,155 @@
|
|||||||
#include "pip.h"
|
#include "pip.h"
|
||||||
|
|
||||||
static const char * smallstr = "abcdef";
|
|
||||||
|
|
||||||
static const char * bigstr = "zsxdcgfhvbncjdbasljcvavcjadnwnxudvbabdhjlavudvdaljsvclavjlasdhvcjhldsavhjldasvfjlhsavdjhavdjhvfjhldasvfjlasvfhjldasvfhjasvfdjdasfhvjldasvhfjlasvfhjlahsvdfhjfvfvdjalsvfjlhasdvfdjsalvfhhjldasvfdjhaldsvfhjdvsfjhlavfjhlavfladlsvfjlasdvfdhjlavfhjldasvfhjlavfhjldvfhjlalsdvfjlhvasfhjlvchjlavchjladvchjldladvschjlladscvjlhdcahjchjllcahjllvcdjladsvhldbcljadsbcjdhlsachjlvdsa hjlcldajc hljdascbhaldb cldhashd l cajlhs chdsbfhlbfdasdffadsfjkbfkjldsabflhbcldhsbhclabchljadsbchldahsbcladsbhclhabhasbclasbdhl";
|
|
||||||
|
|
||||||
PIKbdListener kbd(0, 0, false);
|
|
||||||
#include <iostream>
|
|
||||||
#include <codecvt>
|
|
||||||
|
|
||||||
|
|
||||||
using namespace PICoutManipulators;
|
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
/*PIVariant vi;
|
const int repeat = 1000;
|
||||||
piCout << vi;
|
const int no_repeat = 1;
|
||||||
vi = 1;
|
const int small_cnt = 1000;
|
||||||
piCout << vi << vi.toString();
|
const int big_cnt = 1000000;
|
||||||
vi = "string";
|
|
||||||
piCout << vi << vi.toStringList();
|
|
||||||
vi = PIStringList("2");
|
|
||||||
piCout << vi << vi.toInt();*/
|
|
||||||
|
|
||||||
/*auto cmp = [](const PIConstChars & c0, const PIConstChars & c1){
|
|
||||||
PICout(DefaultControls) << c0 << "==" << c1 << "->" << (c0 != c1);
|
|
||||||
};
|
|
||||||
PIConstChars s;
|
|
||||||
PICout(DefaultControls | AddQuotes) << s;
|
|
||||||
s = PIConstChars("str", 2);
|
|
||||||
PICout(DefaultControls | AddQuotes) << s;
|
|
||||||
cmp(PIConstChars(), PIConstChars());
|
|
||||||
cmp(PIConstChars("str"), PIConstChars());
|
|
||||||
cmp(PIConstChars(), PIConstChars("s_tr"));
|
|
||||||
cmp(PIConstChars("str1"), PIConstChars("str"));
|
|
||||||
cmp(PIConstChars("str"), PIConstChars("str2"));
|
|
||||||
cmp(PIConstChars("str"), PIConstChars("sTr"));
|
|
||||||
cmp(PIConstChars("str"), PIConstChars("str"));
|
|
||||||
cmp(PIConstChars("1a"), PIConstChars("1b"));
|
|
||||||
cmp(PIConstChars("1c"), PIConstChars("1b"));*/
|
|
||||||
|
|
||||||
/*PIMap<PIConstChars, int> map;
|
|
||||||
map[PIConstChars()] = 0;
|
|
||||||
map[PIConstChars()] = -1;
|
|
||||||
map["_2"] = 22;
|
|
||||||
map["1"] = 11;
|
|
||||||
map["__3"] = 33;
|
|
||||||
map["10"] = 10;
|
|
||||||
map[""] = 999;
|
|
||||||
piCout << map;
|
|
||||||
|
|
||||||
piCout << PIConstChars().toString();
|
|
||||||
piCout << PIConstChars("").toString();
|
|
||||||
piCout << PIConstChars("str").toString();
|
|
||||||
PIConstChars s = " 1 2 \t";
|
|
||||||
piCout << "trim:";
|
|
||||||
PICout(DefaultControls | AddQuotes) << s.trimmed();
|
|
||||||
PICout(DefaultControls | AddQuotes) << s;
|
|
||||||
PICout(DefaultControls | AddQuotes) << s.isEmpty();*/
|
|
||||||
|
|
||||||
/*piCout << PIIODevice::availablePrefixes();
|
|
||||||
auto * d = PIIODevice::createFromFullPath("ser://COM1");
|
|
||||||
piCout << "";
|
|
||||||
piCout << d;
|
|
||||||
d->dump();
|
|
||||||
d = PIIODevice::createFromFullPath("eth://udp:127.0.0.1:5000");
|
|
||||||
piCout << "";
|
|
||||||
piCout << d;
|
|
||||||
d->dump();*/
|
|
||||||
|
|
||||||
piCout << "";
|
|
||||||
dumpApplication();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
auto rstr = PIString::fromUTF8("ascii русский!");
|
|
||||||
/*for (PIChar c: rstr)
|
|
||||||
std::wcout << c.toWChar();
|
|
||||||
std::wcout << std::endl;*/
|
|
||||||
piCout << PIChar::fromUTF8("│");
|
|
||||||
piCout << PICoutManipulators::Hex << (int)PIChar::fromUTF8("│").toWChar();
|
|
||||||
piCout << rstr;
|
|
||||||
|
|
||||||
/*char rs[] = "й";
|
|
||||||
piCout << PIString(PIChar::fromUTF8(rs));
|
|
||||||
std::cout << sizeof(rs) << " chars ";
|
|
||||||
for (int i = 0; i < sizeof(rs); ++i)
|
|
||||||
std::cout << "'" << (char)(rs[i]) << "' " << (int)(uchar)(rs[i]);
|
|
||||||
std::cout << std::endl;
|
|
||||||
CONNECTL(&kbd, keyPressed, ([](PIKbdListener::KeyEvent k, void*){
|
|
||||||
;
|
|
||||||
piCout << k.key << PIChar((ushort)k.key);
|
|
||||||
}));
|
|
||||||
kbd.start();
|
|
||||||
WAIT_FOR_EXIT;*/
|
|
||||||
//return 0;
|
|
||||||
static const int cc = 1000000;
|
|
||||||
PITimeMeasurer tm;
|
PITimeMeasurer tm;
|
||||||
int l = 0;
|
|
||||||
tm.reset();
|
|
||||||
for(int i=0; i<cc; ++i) {
|
|
||||||
PIString s(smallstr);
|
|
||||||
l = s.size();
|
|
||||||
}
|
|
||||||
piCout << l << "PIString()" << tm.elapsed_m();
|
|
||||||
tm.reset();
|
|
||||||
for(int i=0; i<cc; ++i) {
|
|
||||||
PIString s = smallstr;
|
|
||||||
l = s.size();
|
|
||||||
}
|
|
||||||
piCout << l << "PIString =" << tm.elapsed_m();
|
|
||||||
tm.reset();
|
|
||||||
for(int i=0; i<cc; ++i) {
|
|
||||||
PIString s = PIStringAscii(smallstr);
|
|
||||||
l = s.size();
|
|
||||||
}
|
|
||||||
piCout << l << "PIStringAscii" << tm.elapsed_m();
|
|
||||||
tm.reset();
|
|
||||||
for(int i=0; i<cc; ++i) {
|
|
||||||
PIString s;
|
|
||||||
s += smallstr;
|
|
||||||
s += "1";
|
|
||||||
l = s.size();
|
|
||||||
}
|
|
||||||
piCout << l << "PIString + PIString" << tm.elapsed_m();
|
|
||||||
tm.reset();
|
|
||||||
for(int i=0; i<cc; ++i) {
|
|
||||||
PIString s = PIStringAscii(smallstr) + "1";
|
|
||||||
l = s.size();
|
|
||||||
}
|
|
||||||
piCout << l << "PIStringAscii + PIString" << tm.elapsed_m();
|
|
||||||
tm.reset();
|
|
||||||
for(int i=0; i<cc; ++i) {
|
|
||||||
PIString s = PIString::fromUTF8(smallstr);
|
|
||||||
l = s.size();
|
|
||||||
}
|
|
||||||
piCout << l << "PIString::fromUTF8" << tm.elapsed_m();
|
|
||||||
tm.reset();
|
|
||||||
for(int i=0; i<cc; ++i) {
|
|
||||||
PIString s = PIString::fromSystem(smallstr);
|
|
||||||
l = s.size();
|
|
||||||
}
|
|
||||||
piCout << l << "PIString::fromSystem" << tm.elapsed_m();
|
|
||||||
tm.reset();
|
|
||||||
for(int i=0; i<cc; ++i) {
|
|
||||||
PIString s = PIString::fromAscii(smallstr);
|
|
||||||
l = s.size();
|
|
||||||
}
|
|
||||||
piCout << l << "PIString::fromAscii" << tm.elapsed_m();
|
|
||||||
|
|
||||||
|
|
||||||
|
piCout << "map<int, int> insert...";
|
||||||
tm.reset();
|
tm.reset();
|
||||||
for(int i=0; i<cc; ++i) {
|
for (int c=0; c<repeat; ++c) {
|
||||||
PIString s(bigstr);
|
PIMap<int, int> m1;
|
||||||
l = s.size();
|
for (int i=0; i<small_cnt; ++i) {
|
||||||
|
m1.insert(i, i);
|
||||||
}
|
}
|
||||||
piCout << l << "PIString()" << tm.elapsed_m();
|
}
|
||||||
|
piCout << "map<int, int> insert" << tm.elapsed_m();
|
||||||
|
piCout << "map<int, int> insert []...";
|
||||||
tm.reset();
|
tm.reset();
|
||||||
for(int i=0; i<cc; ++i) {
|
for (int c=0; c<repeat; ++c) {
|
||||||
PIString s = bigstr;
|
PIMap<int, int> m1;
|
||||||
l = s.size();
|
for (int i=0; i<small_cnt; ++i) {
|
||||||
|
m1[i] = i;
|
||||||
}
|
}
|
||||||
piCout << l << "PIString =" << tm.elapsed_m();
|
}
|
||||||
|
piCout << "map<int, int> insert []" << tm.elapsed_m();
|
||||||
|
piCout << "map<int, int> insert rnd...";
|
||||||
tm.reset();
|
tm.reset();
|
||||||
for(int i=0; i<cc; ++i) {
|
for (int c=0; c<repeat; ++c) {
|
||||||
PIString s = PIStringAscii(bigstr);
|
PIMap<int, int> m1;
|
||||||
l = s.size();
|
for (int i=0; i<small_cnt; ++i) {
|
||||||
|
m1.insert(randomi(), i);
|
||||||
}
|
}
|
||||||
piCout << l << "PIStringAscii" << tm.elapsed_m();
|
}
|
||||||
|
piCout << "map<int, int> insert rnd" << tm.elapsed_m();
|
||||||
|
piCout << "map<int, int> insert rnd []...";
|
||||||
tm.reset();
|
tm.reset();
|
||||||
for(int i=0; i<cc; ++i) {
|
for (int c=0; c<repeat; ++c) {
|
||||||
PIString s;
|
PIMap<int, int> m1;
|
||||||
s += bigstr;
|
for (int i=0; i<small_cnt; ++i) {
|
||||||
s += "1";
|
m1[randomi()] = i;
|
||||||
l = s.size();
|
|
||||||
}
|
}
|
||||||
piCout << l << "PIString + PIString" << tm.elapsed_m();
|
}
|
||||||
|
piCout << "map<int, int> insert rnd []" << tm.elapsed_m();
|
||||||
|
|
||||||
|
piCout << "bigmap<int, int> insert...";
|
||||||
tm.reset();
|
tm.reset();
|
||||||
for(int i=0; i<cc; ++i) {
|
for (int c=0; c<no_repeat; ++c) {
|
||||||
PIString s = PIStringAscii(bigstr) + "1";
|
PIMap<int, int> m1;
|
||||||
l = s.size();
|
for (int i=0; i<big_cnt; ++i) {
|
||||||
|
m1.insert(i, i);
|
||||||
}
|
}
|
||||||
piCout << l << "PIStringAscii + PIString" << tm.elapsed_m();
|
}
|
||||||
|
piCout << "bigmap<int, int> insert" << tm.elapsed_m();
|
||||||
|
piCout << "bigmap<int, int> insert []...";
|
||||||
tm.reset();
|
tm.reset();
|
||||||
for(int i=0; i<cc; ++i) {
|
for (int c=0; c<no_repeat; ++c) {
|
||||||
PIString s = PIString::fromUTF8(bigstr);
|
PIMap<int, int> m1;
|
||||||
l = s.size();
|
for (int i=0; i<big_cnt; ++i) {
|
||||||
|
m1[i] = i;
|
||||||
}
|
}
|
||||||
piCout << l << "PIString::fromUTF8" << tm.elapsed_m();
|
}
|
||||||
|
piCout << "bigmap<int, int> insert []" << tm.elapsed_m();
|
||||||
|
piCout << "bigmap<int, int> insert rnd...";
|
||||||
tm.reset();
|
tm.reset();
|
||||||
for(int i=0; i<cc; ++i) {
|
for (int c=0; c<no_repeat; ++c) {
|
||||||
PIString s = PIString::fromSystem(bigstr);
|
PIMap<int, int> m1;
|
||||||
l = s.size();
|
for (int i=0; i<big_cnt; ++i) {
|
||||||
|
m1.insert(randomi(), i);
|
||||||
}
|
}
|
||||||
piCout << l << "PIString::fromSystem" << tm.elapsed_m();
|
}
|
||||||
|
piCout << "bigmap<int, int> insert rnd" << tm.elapsed_m();
|
||||||
|
piCout << "bigmap<int, int> insert rnd []...";
|
||||||
tm.reset();
|
tm.reset();
|
||||||
for(int i=0; i<cc; ++i) {
|
for (int c=0; c<no_repeat; ++c) {
|
||||||
PIString s = PIString::fromAscii(bigstr);
|
PIMap<int, int> m1;
|
||||||
l = s.size();
|
for (int i=0; i<big_cnt; ++i) {
|
||||||
|
m1[randomi()] = i;
|
||||||
}
|
}
|
||||||
piCout << l << "PIString::fromAscii" << tm.elapsed_m();
|
}
|
||||||
PIString is = PIString::fromAscii(bigstr);
|
piCout << "bigmap<int, int> insert rnd []" << tm.elapsed_m();
|
||||||
|
|
||||||
|
PIStringList small_sl;
|
||||||
|
for (int i=0; i<small_cnt; ++i) small_sl << PIString::fromNumber(randomd());
|
||||||
|
PIStringList big_sl;
|
||||||
|
for (int i=0; i<big_cnt; ++i) big_sl << PIString::fromNumber(randomd());
|
||||||
|
piCout << "map<PIString, int> insert...";
|
||||||
tm.reset();
|
tm.reset();
|
||||||
for(int i=0; i<cc; ++i) {
|
for (int c=0; c<repeat; ++c) {
|
||||||
l = is.toByteArray().size();
|
PIMap<PIString, int> m1;
|
||||||
|
for (int i=0; i<small_cnt; ++i) {
|
||||||
|
m1.insert(small_sl[i], i);
|
||||||
}
|
}
|
||||||
piCout << l << "PIString::toByteArray" << tm.elapsed_m();
|
}
|
||||||
PIByteArray ba = is.toByteArray();
|
piCout << "map<PIString, int> insert" << tm.elapsed_m();
|
||||||
|
piCout << "map<PIString, int> insert []...";
|
||||||
tm.reset();
|
tm.reset();
|
||||||
for(int i=0; i<cc; ++i) {
|
for (int c=0; c<repeat; ++c) {
|
||||||
PIString s = PIString::fromUTF8(ba);
|
PIMap<PIString, int> m1;
|
||||||
l = s.size();
|
for (int i=0; i<small_cnt; ++i) {
|
||||||
|
m1[small_sl[i]] = i;
|
||||||
}
|
}
|
||||||
piCout << l << "PIString::fromByteArray" << tm.elapsed_m();
|
}
|
||||||
|
piCout << "map<PIString, int> insert []" << tm.elapsed_m();
|
||||||
|
|
||||||
|
piCout << "bigmap<PIString, int> insert...";
|
||||||
tm.reset();
|
tm.reset();
|
||||||
for(int i=0; i<cc; ++i) {
|
for (int c=0; c<no_repeat; ++c) {
|
||||||
PIString s = PIString::fromNumber(ba.size());
|
PIMap<PIString, int> m1;
|
||||||
l = s.size();
|
for (int i=0; i<big_cnt; ++i) {
|
||||||
|
m1.insert(big_sl[i], i);
|
||||||
}
|
}
|
||||||
piCout << l << "PIString::fromNumber" << tm.elapsed_m();
|
}
|
||||||
|
piCout << "bigmap<PIString, int> insert" << tm.elapsed_m();
|
||||||
|
piCout << "bigmap<PIString, int> insert []...";
|
||||||
tm.reset();
|
tm.reset();
|
||||||
for(int i=0; i<cc; ++i) {
|
for (int c=0; c<no_repeat; ++c) {
|
||||||
PIString s = is;
|
PIMap<PIString, int> m1;
|
||||||
l = s.size();
|
for (int i=0; i<big_cnt; ++i) {
|
||||||
|
m1[big_sl[i]] = i;
|
||||||
}
|
}
|
||||||
piCout << l << "PIString::assign empty" << tm.elapsed_m();
|
}
|
||||||
PIString is2 = PIString::fromUTF8(ba);
|
piCout << "bigmap<PIString, int> insert []" << tm.elapsed_m();
|
||||||
|
|
||||||
|
|
||||||
|
PIMap<int, int> m1;
|
||||||
|
for (int i=0; i<big_cnt; ++i) m1.insert(i,i);
|
||||||
|
piCout << "map<int, int> interate...";
|
||||||
tm.reset();
|
tm.reset();
|
||||||
for(int i=0; i<cc; ++i) {
|
for (int c=0; c<repeat; ++c) {
|
||||||
PIString s = is;
|
PIVector<int> v;
|
||||||
l = s.size();
|
v.reserve(m1.size());
|
||||||
s = is2;
|
auto it = m1.makeIterator();
|
||||||
l += s.size();
|
while (it.next()) v << it.value();
|
||||||
}
|
}
|
||||||
piCout << l << "PIString::assign non empty" << tm.elapsed_m();
|
piCout << "map<int, int> interate" << tm.elapsed_m();
|
||||||
|
|
||||||
|
PIMap<PIString, int> m2;
|
||||||
|
for (int i=0; i<big_cnt; ++i) {
|
||||||
|
m2.insert(big_sl[i], i);
|
||||||
|
}
|
||||||
|
piCout << "map<PIString, int> interate...";
|
||||||
|
tm.reset();
|
||||||
|
for (int c=0; c<repeat; ++c) {
|
||||||
|
PIVector<int> v;
|
||||||
|
v.reserve(m2.size());
|
||||||
|
auto it = m2.makeIterator();
|
||||||
|
while (it.next()) v << it.value();
|
||||||
|
}
|
||||||
|
piCout << "map<PIString, int> interate" << tm.elapsed_m();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user