.benchmarks

git-svn-id: svn://ultimatepp.org/upp/trunk@15214 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2020-10-07 19:03:12 +00:00
parent 7c5baaaffb
commit d7ce8b7e8f
3 changed files with 96 additions and 10 deletions

View file

@ -0,0 +1,45 @@
#include <Core/Core.h>
#include <TestData/TestData.h>
#include <set>
#include <unordered_set>
#include <vector>
using namespace Upp;
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
Vector<String> w = AliceWords();
std::vector<std::string> q;
for(auto s : w)
q.push_back(s.ToStd());
for(int i = 0; i < 100; i++) {
Index<String> ndx;
std::set<std::string> st;
std::set<std::string> hst;
{
RTIMING("Index");
for(const String& s : w)
ndx.FindAdd(s);
}
{
RTIMING("set");
for(const std::string& s : q)
st.insert(s);
}
{
RTIMING("unordered_set");
for(const std::string& s : q)
hst.insert(s);
}
ONCELOCK {
RDUMP(ndx.GetCount());
RDUMP(st.size());
RDUMP(hst.size());
}
}
}

View file

@ -0,0 +1,10 @@
uses
Core,
TestData;
file
IndexStd.cpp;
mainconfig
"" = "";

View file

@ -6,41 +6,38 @@ using namespace Upp;
CONSOLE_APP_MAIN
{
const int N = 2500;
const int N = 200;
Buffer<String> data(N);
Vector<String> data;
Buffer<std::string> sdata(N);
for(int i = 0; i < N; i++) {
data[i] = AsString(i);
data << AsString(i);
sdata[i] = data[i].ToStd();
}
RDUMP(sizeof(std::string));
RDUMP(sizeof(String));
for(int j = 0; j < N; j++) {
for(int q = 100000; q--;) {
{
RTIMING("vector<string>::push_back");
std::vector<std::string> v;
for(int i = 0; i < j; i++)
for(int i = 0; i < N; i++)
v.push_back(sdata[i]);
}
{
RTIMING("vector<String>::push_back");
std::vector<String> v;
for(int i = 0; i < j; i++)
for(int i = 0; i < N; i++)
v.push_back(data[i]);
}
{
RTIMING("Vector<String>::Add");
Vector<String> v;
for(int i = 0; i < j; i++)
for(int i = 0; i < N; i++)
v.Add(data[i]);
}
}
for(int j = 0; j < 100; j++) {
{
RTIMING("vector<string>::insert");
std::vector<std::string> v;
@ -59,5 +56,39 @@ CONSOLE_APP_MAIN
for(int i = 0; i < N; i++)
v.Insert(0, data[i]);
}
{
std::vector<std::string> v;
for(int i = 0; i < N; i++)
v.insert(v.begin(), sdata[i]);
RTIMING("vector<string>::erase");
while(v.size())
v.erase(v.begin());
}
{
std::vector<String> v(~sdata, ~sdata + N);
RTIMING("vector<String>::erase");
while(v.size())
v.erase(v.begin());
}
{
Vector<String> v;
for(int i = 0; i < N; i++)
v.Insert(0, data[i]);
RTIMING("Vector<String>::Remove");
while(v.GetCount())
v.Remove(0);
}
for(int j = 0; j < 100; j++) {
{
std::vector<std::string> v(~sdata, ~sdata + N);
RTIMING("std::remove_if");
v.erase(std::remove_if(v.begin(), v.end(), [](const std::string& h) { return h[0] == '1'; }), v.end());
}
{
Vector<String> v = clone(data);
RTIMING("Vector::RemoveIf");
v.RemoveIf([&](int i) { return v[i][0] == '1'; });
}
}
}
}