From adf46bd64e1d0ee6707ea3ef23d990c4a3ca91db Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 4 Oct 2016 08:34:25 +0000 Subject: [PATCH] .benchmarks git-svn-id: svn://ultimatepp.org/upp/trunk@10262 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- benchmarks/BenchOps/BenchOps.cpp | 37 +++++++++++++++------------- benchmarks/BenchOps/BenchOps.upp | 5 +++- benchmarks/CoSort/CoSort.cpp | 2 ++ benchmarks/LZ4/LZ4.cpp | 39 ++++++++++++++++++++++++++++++ benchmarks/LZ4/LZ4.upp | 10 ++++++++ benchmarks/LZ4/init | 5 ++++ benchmarks/SortIndex/SortIndex.cpp | 25 +++++++++++++++++++ benchmarks/SortIndex/SortIndex.upp | 9 +++++++ benchmarks/SortIndex/init | 5 ++++ 9 files changed, 119 insertions(+), 18 deletions(-) create mode 100644 benchmarks/LZ4/LZ4.cpp create mode 100644 benchmarks/LZ4/LZ4.upp create mode 100644 benchmarks/LZ4/init create mode 100644 benchmarks/SortIndex/SortIndex.cpp create mode 100644 benchmarks/SortIndex/SortIndex.upp create mode 100644 benchmarks/SortIndex/init diff --git a/benchmarks/BenchOps/BenchOps.cpp b/benchmarks/BenchOps/BenchOps.cpp index 99e912d25..a6fada42d 100644 --- a/benchmarks/BenchOps/BenchOps.cpp +++ b/benchmarks/BenchOps/BenchOps.cpp @@ -6,14 +6,13 @@ Atomic val; struct Data { int64 val[4]; + int xxx; void Zero() { val[0] = val[1] = val[2] = val[3] = 0; } }; Data src[16], dst[16]; -int count; - #define N 10000000 int count; @@ -32,14 +31,24 @@ force_inline void SSEZero32(void *t) CONSOLE_APP_MAIN { { - RTIMING("Atomic inc/dec"); + RTIMING("Atomic Inc+Dec"); for(int i = 0; i < N; i++) { AtomicInc(val); AtomicDec(val); } } { -<<<<<<< .mine + RTIMING("Atomic Inc+Dec+test (unstable)"); + for(int i = 0; i < N; i++) { + if(i & 1) { + AtomicInc(val); + AtomicInc(val); + } + if(AtomicDec(val)) + count++; + } + } + { RTIMING("Read (no locking)"); for(int i = 0; i < N; i++) { count += src[i & 15].val[0]; @@ -59,19 +68,6 @@ CONSOLE_APP_MAIN } } { -======= - RTIMING("Atomic and test"); - for(int i = 0; i < N; i++) { - if(i & 1) { - AtomicInc(val); - AtomicInc(val); - } - if(AtomicDec(val)) - count++; - } - } - { ->>>>>>> .r9514 static StaticMutex mtx; RTIMING("StaticMutex"); for(int i = 0; i < N; i++) { @@ -183,4 +179,11 @@ CONSOLE_APP_MAIN dst[i & 3] = src[i & 3]; } } + { + int n = Random(); + RTIMING("Divide"); + for(int i = 0; i < N; i++) { + dst[i & 15].xxx = src[i & 15].xxx / n; + } + } } diff --git a/benchmarks/BenchOps/BenchOps.upp b/benchmarks/BenchOps/BenchOps.upp index d4f5979e6..0189e874a 100644 --- a/benchmarks/BenchOps/BenchOps.upp +++ b/benchmarks/BenchOps/BenchOps.upp @@ -2,7 +2,10 @@ uses Core; file - BenchOps.cpp optimize_speed; + BenchOps.cpp.mine, + BenchOps.cpp.r10063, + BenchOps.cpp.r10157, + BenchOps.cpp; mainconfig "" = "MT"; diff --git a/benchmarks/CoSort/CoSort.cpp b/benchmarks/CoSort/CoSort.cpp index 9febc20a5..a24d07378 100644 --- a/benchmarks/CoSort/CoSort.cpp +++ b/benchmarks/CoSort/CoSort.cpp @@ -30,6 +30,7 @@ CONSOLE_APP_MAIN RLOG("CoSort " << tm); } +#ifdef CPU_64 { CoWork::SetPoolSize(400); auto h1 = clone(h); @@ -37,6 +38,7 @@ CONSOLE_APP_MAIN CoSort(h1); RLOG("CoSort (big pool) " << tm); } +#endif Thread::ShutdownThreads(); RLOG("Exit"); diff --git a/benchmarks/LZ4/LZ4.cpp b/benchmarks/LZ4/LZ4.cpp new file mode 100644 index 000000000..f28a45ad3 --- /dev/null +++ b/benchmarks/LZ4/LZ4.cpp @@ -0,0 +1,39 @@ +#include +#include + +using namespace Upp; + +CONSOLE_APP_MAIN +{ + StdLogSetup(LOG_COUT|LOG_FILE); + + TimeStop tm; + String s = LoadFile(GetHomeDirFile("testdata/c12_OCOE_env.blb")); + + RLOG("Loaded in " << tm << " s"); + + s.Cat(s); + + RLOG("Original size " << s.GetCount() / 1024 / 1024 << " MB"); + + { + TimeStop tm; + String c = LZ4Compress(s); + RLOG("Compresss " << s.GetLength() / tm.Seconds() / 1024/1024 << " MB / s"); + RLOG("Compressed size " << c.GetCount() / 1024 / 1024 << " MB (" << (100.0 * c.GetCount() / s.GetCount()) << "%)"); + tm.Reset(); + String d = LZ4Decompress(c); + RLOG("DeCompresss " << s.GetLength() / tm.Seconds() / 1024/1024 << " MB / s"); + ASSERT(s == d); + } + { + TimeStop tm; + String c = CoLZ4Compress(s); + RLOG("CoCompresss " << s.GetLength() / tm.Seconds() / 1024/1024 << " MB / s"); + RLOG("Compressed size " << c.GetCount() / 1024 / 1024 << " MB (" << (100.0 * c.GetCount() / s.GetCount()) << "%)"); + tm.Reset(); + String d = CoLZ4Decompress(c); + RLOG("CoDeCompresss " << s.GetLength() / tm.Seconds() / 1024/1024 << " MB / s"); + ASSERT(s == d); + } +} diff --git a/benchmarks/LZ4/LZ4.upp b/benchmarks/LZ4/LZ4.upp new file mode 100644 index 000000000..1bdd5a0fb --- /dev/null +++ b/benchmarks/LZ4/LZ4.upp @@ -0,0 +1,10 @@ +uses + Core, + plugin/lz4; + +file + LZ4.cpp; + +mainconfig + "" = "MT"; + diff --git a/benchmarks/LZ4/init b/benchmarks/LZ4/init new file mode 100644 index 000000000..b5389d5e8 --- /dev/null +++ b/benchmarks/LZ4/init @@ -0,0 +1,5 @@ +#ifndef _LZ4_icpp_init_stub +#define _LZ4_icpp_init_stub +#include "Core/init" +#include "plugin/lz4/init" +#endif diff --git a/benchmarks/SortIndex/SortIndex.cpp b/benchmarks/SortIndex/SortIndex.cpp new file mode 100644 index 000000000..d6d637b8b --- /dev/null +++ b/benchmarks/SortIndex/SortIndex.cpp @@ -0,0 +1,25 @@ +#include + +using namespace Upp; + +CONSOLE_APP_MAIN +{ + Index n; + Vector v; + + for(int i = 0; i < 10000000; i++) { + String s = AsString(Random()); + n.Add(s); + v.Add(s); + } + + { + RTIMING("Sort"); + Sort(v); + } + + { + RTIMING("IndexSort"); + SortIndex(n); + } +} diff --git a/benchmarks/SortIndex/SortIndex.upp b/benchmarks/SortIndex/SortIndex.upp new file mode 100644 index 000000000..b6050f149 --- /dev/null +++ b/benchmarks/SortIndex/SortIndex.upp @@ -0,0 +1,9 @@ +uses + Core; + +file + SortIndex.cpp; + +mainconfig + "" = ""; + diff --git a/benchmarks/SortIndex/init b/benchmarks/SortIndex/init new file mode 100644 index 000000000..c0eab6712 --- /dev/null +++ b/benchmarks/SortIndex/init @@ -0,0 +1,5 @@ +#ifndef _SortIndex_icpp_init_stub +#define _SortIndex_icpp_init_stub +#include "Core/init" +#include "Geom/Coords/init" +#endif