#include <QtCore/QCoreApplication>
#include <vector>
#include <QString>
#include <string>
#include <QUuid>
#include <QDebug>
#include "TimerForPerf.h"
#include "YChrono.h"
#include <YFile.h>
#include <map>
#include <unordered_map>
#include "YContainer.h"
/************************************************************************/
/* vector容器的主程序 */
/*
/************************************************************************/
/*
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
using namespace std;
vector<QString> vec;
for (int i = 0; i < 20000; i++)
{
QString strPath = R"(C:\Windows\WinSxS\wow64_microsoft-windows-net1-command-line-tool_31bf3856ad364e35_10.0.22621.674_none_f3295365522a1782\r\))";
QUuid id = QUuid::createUuid();
QString strGuid = id.toString();
strPath += strGuid;
strPath += ".exe";
vec.push_back(strPath);
}
// 查询耗时测试
vector<LONGLONG> vecCost;
QString strTarget = R"(C:\Windows\WinSxS\wow64_microsoft-windows-net1-command-line-tool_31bf3856ad364e35_10.0.22621.674_none_f3295365522a1782\r\))";
QUuid id = QUuid::createUuid();
QString strGuid = id.toString();
strTarget += strGuid;
strTarget += ".exe";
for (int j = 0; j < 100;j++)
{
//TimerForPerf t;
YChrono yc;
yc.Start();
for (auto it = vec.begin(); it != vec.end(); ++it)
{
if (*it == strTarget)
{
qDebug() << "Find Success :" << strTarget << endl;
break;
}
}
yc.End();
//qDebug() << "End Find : Consuming:"<< t.elapsed_nano() << endl; //打印微秒
qDebug() << "End Find : Consuming:" << yc.costTime << endl; //打印微秒
vecCost.push_back(yc.costTime);
}
YFile yfile("d:\\1.csv");
LONGLONG allCost = 0;
for (auto it = vecCost.begin(); it != vecCost.end();it++)
{
allCost += *it;
yfile.m_f << std::to_string(*it) << ",\n";
}
qDebug() << "All Consuming:" << allCost << endl; //打印微秒
return a.exec();
}
*/
/************************************************************************/
/* map容器 */
/************************************************************************/
// T自定义的容器类
// 文件名 指定输出结果的文件名
// wTarget 指定查找的字符串
// count 指定查找次数
template<class T>
void testCase(T& ycontainer, const char* filename, wstring wTarget, long count = 1000)
{
// 1填充数据
ycontainer.FillData();
vector<double> vecCost;
// 1循环查找
for (int j = 0; j < 1000; j++)
{
ycontainer.CommonFind(wTarget);// 调用查找函数
qDebug() << "End Find : Consuming:" << ycontainer.m_yChrono.costTime << endl; //打印微秒
vecCost.push_back((double)ycontainer.m_yChrono.costTime);
}
YFile yfile(filename); // ("d:\\vector.csv");
LONGLONG allCost = 0;
for (auto it = vecCost.begin(); it != vecCost.end(); it++)
{
allCost += *it;
yfile.m_f << std::to_string(*it) << ",\n";
}
qDebug() << "All Consuming:" << allCost << endl; //打印微秒
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// 查找元素
QString strTarget = R"(C:\Windows\WinSxS\wow64_microsoft-windows-net1-command-line-tool_31bf3856ad364e35_10.0.22621.674_none_f3295365522a1782\r\))";
QUuid id = QUuid::createUuid();
QString strGuid = id.toString();
strTarget += strGuid;
strTarget += ".exe";
wstring & wTarget = strTarget.toStdWString();
// vector容器
YContainer<vector<wstring>> yVector;
testCase<YContainer<vector<wstring>>>(yVector, "D:\\vector.csv", wTarget);
// map容器
YContainer<map<wstring, bool>> yMap;
testCase<YContainer<map<wstring, bool>>>(yMap, "D:\\map.csv", wTarget);
// hash_map容器
YContainer<hash_map<wstring, bool>> yHash_Map;
testCase<YContainer<hash_map<wstring, bool>>>(yHash_Map, "D:\\hash-map.csv", wTarget);
// unordered_map 容器
YContainer<unordered_map<wstring, bool>> yUnordered_Map;
testCase<YContainer<unordered_map<wstring, bool>>>(yUnordered_Map, "D:\\unordered—map.csv", wTarget);
return a.exec();
}
/*
using namespace std;
map<QString, bool> vec;
for (int i = 0; i < 20000; i++)
{
QString strPath = R"(C:\Windows\WinSxS\wow64_microsoft-windows-net1-command-line-tool_31bf3856ad364e35_10.0.22621.674_none_f3295365522a1782\r\))";
QUuid id = QUuid::createUuid();
QString strGuid = id.toString();
strPath += strGuid;
strPath += ".exe";
vec[strPath] = true;
}
// 查询耗时测试
vector<LONGLONG> vecCost;
QString strTarget = R"(C:\Windows\WinSxS\wow64_microsoft-windows-net1-command-line-tool_31bf3856ad364e35_10.0.22621.674_none_f3295365522a1782\r\))";
QUuid id = QUuid::createUuid();
QString strGuid = id.toString();
strTarget += strGuid;
strTarget += ".exe";
for (int j = 0; j < 100; j++)
{
//TimerForPerf t;
YChrono yc;
yc.Start();
if (vec.find(strTarget) != vec.end())
{
qDebug() << "Find Success :" << strTarget << endl;
break;
}
yc.End();
//qDebug() << "End Find : Consuming:"<< t.elapsed_nano() << endl; //打印微秒
qDebug() << "End Find : Consuming:" << yc.costTime << endl; //打印微秒
vecCost.push_back((LONGLONG)yc.costTime);
}
//{{ 查找已存在项
//YChrono yc;
//yc.Start();
//if (vec.find(vec.rbegin()->first) != vec.end())
//{
// qDebug() << "Find Success, Key = " << vec.rbegin()->first << " value = " <<vec[vec.rbegin()->first] << endl;
//}
//yc.End();
////qDebug() << "End Find : Consuming:"<< t.elapsed_nano() << endl; //打印微秒
//qDebug() << "End Find : Consuming:" << yc.costTime << endl; //打印微秒
//vecCost.push_back((LONGLONG)yc.costTime);
//}}
YFile yfile("d:\\2.csv");
LONGLONG allCost = 0;
for (auto it = vecCost.begin(); it != vecCost.end(); it++)
{
allCost += *it;
yfile.m_f << std::to_string(*it) << ",\n";
}
qDebug() << "All Consuming:" << allCost << endl; //打印微秒
return a.exec();
}
*/
//int main(int argc, char *argv[])
//{
// QCoreApplication a(argc, argv);
//
// using namespace std;
// unordered_map<LONG32 ,QString > vec;
// for (int i = 0; i < 20000; i++)
// {
// QString strPath = R"(C:\Windows\WinSxS\wow64_microsoft-windows-net1-command-line-tool_31bf3856ad364e35_10.0.22621.674_none_f3295365522a1782\r\))";
// QUuid id = QUuid::createUuid();
// QString strGuid = id.toString();
// strPath += strGuid;
// strPath += ".exe";
// vec[i] = strPath;
// }
//
// // 查询耗时测试
// vector<LONGLONG> vecCost;
//
// QString strTarget = R"(C:\Windows\WinSxS\wow64_microsoft-windows-net1-command-line-tool_31bf3856ad364e35_10.0.22621.674_none_f3295365522a1782\r\))";
// QUuid id = QUuid::createUuid();
// QString strGuid = id.toString();
// strTarget += strGuid;
// strTarget += ".exe";
// for (int j = 0; j < 10000; j++)
// {
// //TimerForPerf t;
// YChrono yc;
// yc.Start();
//
// for (auto it = vec.begin(); it != vec.end(); ++it)
// {
// if (it->second == strTarget)
// {
// qDebug() << "Find Success :" << strTarget << endl;
// break;
// }
// }
// yc.End();
// //qDebug() << "End Find : Consuming:"<< t.elapsed_nano() << endl; //打印微秒
// qDebug() << "End Find : Consuming:" << yc.costTime << endl; //打印微秒
// vecCost.push_back(yc.costTime);
// }
// YFile yfile("d:\\2.csv");
//
// LONGLONG allCost = 0;
// for (auto it = vecCost.begin(); it != vecCost.end(); it++)
// {
// allCost += *it;
// yfile.m_f << std::to_string(*it) << ",\n";
// }
//
// qDebug() << "All Consuming:" << allCost << endl; //打印微秒
//
// return a.exec();
//}