.benchmarks

git-svn-id: svn://ultimatepp.org/upp/trunk@15204 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2020-10-05 11:10:35 +00:00
parent bcbc63157e
commit d273b3d97d
10 changed files with 3695 additions and 89 deletions

View file

@ -0,0 +1,21 @@
#include <Core/Core.h>
using namespace Upp;
#define LDUMP(x) x
template <class T>
String AsHash(const T& x)
{
Sha1Stream s;
const_cast<T&>(x).Serialize(s);
return s.FinishString();
}
CONSOLE_APP_MAIN
{
Pointf x(1, 2);
DDUMP(AsHash(x));
DDUMP(AsHash(Pointf(1, 2)));
DDUMP(AsHash(Pointf(2, 2)));
}

View file

@ -0,0 +1,9 @@
uses
Core;
file
HashBench.cpp;
mainconfig
"" = "";

View file

@ -1,98 +1,29 @@
#include <Core/Core.h>
#include <TestData/TestData.h>
#include <algorithm>
#include <vector>
using namespace Upp;
template <class I, class T>
void Sort__(I begin, I end, const T&)
{
Sort(begin, end, StdLess<T>());
}
template <class I>
void Sort(I begin, I end)
{
Sort__(begin, end, *begin);
}
#define BM_(k, x1, x, sort) { d1 <<= d; RTIMING(k); sort(d1); }
#define BV(k, sort) BM_(k " " #sort " Vector<String>", d1, d, sort)
#define BA(k, sort) BM_(k " " #sort " Array<String>", a1, a, sort)
#define Bv(k, sort) { s1 = s; RTIMING(k " " #sort " vector<string>"); sort(s1.begin(), s1.end()); }
#define BS(k, sort) { d1 <<= d; RTIMING(k " " #sort " Vector<String>"); sort(d1.Begin(), d1.End()); }
#define NN 10
#define Bm(k)\
for(int i = 0; i < NN; i++) { \
Bv(k, std::sort)\
Bv(k, Sort)\
BS(k, std::sort)\
BV(k, Sort)\
}
/*
BV(k, GetStableSortOrderCmp)\
BV(k, StableSortCmp)\
BV(k, Sort)\
BV(k, GetSortOrder)\
BV(k, StableSort)\
BV(k, GetStableSortOrder)\
BA(k, Sort)\
BA(k, StableSort)\
BA(k, StableSortCmp)\
Bv(k, std::sort)\
Bv(k, std::stable_sort)\
Bv(k, Sort)\
BS(k, std::stable_sort)\
*/
#define N 20
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
for(int q = 1; q < N; q++) {
Vector<String> d, d1;
Array<String> a, a1;
std::vector<std::string> s, s1;
for(int i = 0; i < 2000 * q; i++) {
String x = AsString(rand());
d.Add(x);
a.Add(x);
s.push_back(to_string(x));
// StdLogSetup(LOG_COUT|LOG_FILE);
for(int i = 0; i < 1000; i++) {
Vector<String> w = AliceWords();
{
std::vector<std::string> x;
for(auto s : w)
x.push_back(s.ToStd());
RTIMING("std::sort std::vector<std::string>");
std::sort(x.begin(), x.end());
}
RLOG("S" << q);
Bm("S");
}
for(int q = 1; q < N; q++) {
Vector<String> d, d1;
std::vector<std::string> s, s1;
for(int i = 0; i < 2000 * q; i++) {
String x = AsString(rand()) + AsString(rand()) + AsString(rand()) + AsString(rand()) + AsString(rand());
d.Add(x);
s.push_back(to_string(x));
{
RTIMING("Sort Vector<String>");
Sort(w);
}
RLOG("M" << q);
Bm("M");
}
for(int q = 1; q < N; q++) {
Vector<String> d, d1;
std::vector<std::string> s, s1;
for(int i = 0; i < 2000 * q; i++) {
String x = AsString(rand()) + AsString(rand()) + AsString(rand()) + AsString(rand()) + AsString(rand())
+ AsString(rand()) + AsString(rand()) + AsString(rand()) + AsString(rand()) + AsString(rand())
+ AsString(rand()) + AsString(rand()) + AsString(rand()) + AsString(rand()) + AsString(rand())
+ AsString(rand()) + AsString(rand()) + AsString(rand()) + AsString(rand()) + AsString(rand());
d.Add(x);
s.push_back(to_string(x));
ONCELOCK {
RDUMPC(w);
}
RLOG("L" << q);
Bm("L");
}
}

View file

@ -1,5 +1,6 @@
uses
Core;
Core,
TestData;
file
Sort.cpp;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,12 @@
#include "TestData.h"
Vector<String> AliceWords()
{
return Split(alice_text, [](int c) { return c > 32 ? 0 : c; });
}
Vector<String> AliceLines()
{
Vector<String> s = Split(Filter(alice_text, [](int c) { return c == '\r' ? 0 : c; }), '\n');
return s;
}

View file

@ -0,0 +1,13 @@
#ifndef _TestData_TestData_h
#define _TestData_TestData_h
#include <Core/Core.h>
using namespace Upp;
extern const char alice_text[];
Vector<String> AliceWords();
Vector<String> AliceLines();
#endif

View file

@ -0,0 +1,5 @@
file
TestData.h,
Alice.cpp,
Data.cpp;

View file

@ -1,4 +1,15 @@
OLD: VectorMap time: 5742398 ms
NEW: VectorMap time: 5888610 ms
* C:\upp\out\benchmarks\CLANGx64.Blitz.Debug_Full.Release\idmapBench.exe 30.08.2020 10:31:20, user: cxl
VectorMap time: 5524707 ms
STL hash_map time: 3272627 ms
STL map time: 4835707 ms
ValueMap time: 2423032 ms
SortedVectorMap time: 5366781 ms
VectorMap time: 1365093 ms
* C:\upp\out\benchmarks\CLANGx64.Blitz.Debug_Full.Release.Usemalloc\idmapBench.exe 30.08.2020 10:32:18, user: cxl
STL hash_map time: 4058483 ms
STL map time: 5616567 ms
ValueMap time: 3364236 ms
SortedVectorMap time: 6401656 ms
VectorMap time: 2260672 ms

View file

@ -338,7 +338,7 @@ CONSOLE_APP_MAIN
#endif
#if 0
#if 1
{
TimeStop tm;
for(int n = 0; n < N; n++)