diff --git a/benchmarks/BenchOps/BenchOps.cpp b/benchmarks/BenchOps/BenchOps.cpp index 0f89a35da..67b27a70a 100644 --- a/benchmarks/BenchOps/BenchOps.cpp +++ b/benchmarks/BenchOps/BenchOps.cpp @@ -17,6 +17,7 @@ Data src[16], dst[16]; int count; +/* force_inline void SSEZero16(void *t) { _mm_storeu_si128((__m128i*)t, _mm_setzero_si128()); @@ -27,6 +28,7 @@ force_inline void SSEZero32(void *t) _mm_storeu_si128((__m128i*)t, _mm_setzero_si128()); _mm_storeu_si128((__m128i*)t + 1, _mm_setzero_si128()); } +*/ CONSOLE_APP_MAIN { @@ -100,6 +102,12 @@ CONSOLE_APP_MAIN MemoryFree32(MemoryAlloc32()); } } + { + for(int i = 0; i < 100; i++) { + RTIMING("Alloc/Free huge"); + delete[] new byte[300000]; + } + } { RTIMING("Alloc/Free large"); for(int i = 0; i < N; i++) { @@ -124,7 +132,7 @@ CONSOLE_APP_MAIN dst[i & 15].Zero(); } } - { +/* { RTIMING("SSEZero32"); for(int i = 0; i < N; i++) { SSEZero32(&dst[i & 15]); @@ -136,7 +144,7 @@ CONSOLE_APP_MAIN SSEZero16(&dst[i & 15]); } } - { +*/ { RTIMING("Copy32"); for(int i = 0; i < N; i++) { dst[i & 15] = src[i & 15]; @@ -186,4 +194,11 @@ CONSOLE_APP_MAIN dst[i & 15].xxx = src[i & 15].xxx / n; } } + { + int n = Random(); + RTIMING("Mul"); + for(int i = 0; i < N; i++) { + dst[i & 15].xxx = src[i & 15].xxx * n; + } + } } diff --git a/benchmarks/CoWork/CoWork.cpp b/benchmarks/CoWork/CoWork.cpp new file mode 100644 index 000000000..e25f823d6 --- /dev/null +++ b/benchmarks/CoWork/CoWork.cpp @@ -0,0 +1,85 @@ +#include + +using namespace Upp; + +force_inline double Sum(const String& s) +{ + CParser p(s); + double sum = 0; + while(!p.IsEof()) + sum += p.ReadDouble(); + return sum; +} + +CONSOLE_APP_MAIN +{ + SeedRandom(0); + Vector data; + for(int i = 0; i < 10000000; i++) { + int n = Random(7); + data.Add(); + for(int j = 0; j < n; j++) + data.Top() << Random() << ' '; + } + +// for(int i = 0; i < 10000; i++) + { + { + double sum = 0; + { + RTIMING("Single thread"); + for(const String& s : data) + sum += Sum(s); + } +// RDUMP(sum); + } + if(0) { + double sum = 0; + { + RTIMING("CoWork"); + CoWork co; + for(const String& s : data) + co & [=, &sum] { + double m = Sum(s); + CoWork::FinLock(); + sum += m; + }; + } +// RDUMP(sum); + } + { + double sum = 0; + { + RTIMING("CoPartition"); + CoWork co; + CoPartition(0, data.GetCount(), + [&](int l, int h) { + double m = 0; + for(int j = l; j < h; j++) + m += Sum(data[j]); + CoWork::FinLock(); + sum += m; + }); + } +// RDUMP(sum); + } + { + double sum = 0; + + { + RTIMING("CoIndex"); + + CoWork co; + co * [&] { + double m = 0; + int i; + while((i = co.Next()) < data.GetCount()) + m += Sum(data[i]); + CoWork::FinLock(); + sum += m; + }; + } +// RDUMP(sum); + } + } +} diff --git a/benchmarks/CoWork/CoWork.upp b/benchmarks/CoWork/CoWork.upp new file mode 100644 index 000000000..a118efc04 --- /dev/null +++ b/benchmarks/CoWork/CoWork.upp @@ -0,0 +1,9 @@ +uses + Core; + +file + CoWork.cpp; + +mainconfig + "" = ""; + diff --git a/benchmarks/LionBenchmark/LionBenchmark.upp b/benchmarks/LionBenchmark/LionBenchmark.upp index 8f097bffa..1b0b8fa12 100644 --- a/benchmarks/LionBenchmark/LionBenchmark.upp +++ b/benchmarks/LionBenchmark/LionBenchmark.upp @@ -5,7 +5,8 @@ uses file LionBenchmark.h, lion.cpp, - main.cpp; + main.cpp, + info.txt; mainconfig "" = "GUI MT"; diff --git a/benchmarks/LionBenchmark/info.txt b/benchmarks/LionBenchmark/info.txt new file mode 100644 index 000000000..49b89a035 --- /dev/null +++ b/benchmarks/LionBenchmark/info.txt @@ -0,0 +1,90 @@ +Standard 0.982318271119843 +MT 1.08342361863489 +========== PAINT +TIMING Fill : 213.86 ms - 46.29 us (214.00 ms / 4620 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 4620 +TIMING Rasterize : 174.86 ms - 37.85 us (175.00 ms / 4620 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 4620 +TIMING Create : 167.07 ms - 5.30 us (168.00 ms / 31511 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 31511 + + +--------------------------------------- +RMAP + +data.GetCount() = 132 +Standard 1.38888888888889 +MT 0.8424599831508 +========== PAINT +TIMING Fill : 194.82 ms - 32.80 us (195.00 ms / 5940 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 5940 +TIMING Rasterize : 398.82 ms - 67.14 us (399.00 ms / 5940 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 5940 +TIMING Create : 2.81 ms - 70.28 ns ( 4.00 ms / 39925 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 39925 + + +--------------------------------------- +RINDEX + +Standard 1.18906064209275 +MT 0.768049155145929 +========== PAINT +TIMING Fill : 248.82 ms - 38.19 us (249.00 ms / 6515 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 6515 +TIMING Rasterize : 325.82 ms - 50.01 us (326.00 ms / 6515 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 6515 +TIMING Create : 9.81 ms - 223.66 ns (11.00 ms / 43841 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 43841 + +-------------------------------------- +RPTR + +Standard 1.0989010989011 +MT 0.727272727272727 +========== PAINT +TIMING Fill : 276.81 ms - 40.26 us (277.00 ms / 6875 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 6875 +TIMING Rasterize : 285.81 ms - 41.57 us (286.00 ms / 6875 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 6875 +TIMING Create : 16.71 ms - 361.11 ns (18.00 ms / 46287 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 46287 + +-------------------------------------- +RPTR 64 + +Standard 1.08342361863489 +MT 0.612745098039216 +========== PAINT +TIMING Fill : 139.88 ms - 28.57 us (140.00 ms / 4896 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 4896 +TIMING Rasterize : 253.88 ms - 51.85 us (254.00 ms / 4896 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 4896 +TIMING Create : 46.29 ms - 432.60 ns (49.00 ms / 107005 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 107005 + +-------------------------------------- +RPTR 64 memset + +Standard 1.06951871657754 +MT 0.607533414337789 +========== PAINT +TIMING Fill : 145.88 ms - 29.54 us (146.00 ms / 4938 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 4938 +TIMING Rasterize : 297.88 ms - 60.32 us (298.00 ms / 4938 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 4938 +TIMING Create : 38.30 ms - 354.90 ns (41.00 ms / 107927 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 107927 + +-------------------------------------- +RPTR 64 memset, looper + +Standard 1.07066381156317 +MT 0.573065902578796 +========== PAINT +TIMING Fill : 361.86 ms - 69.08 us (362.00 ms / 5238 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 5238 +TIMING Rasterize : 296.86 ms - 56.67 us (297.00 ms / 5238 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 5238 +TIMING Create : 51.87 ms - 453.28 ns (55.00 ms / 114425 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 114425 + +------------------------------- +FINAL 64 + 96 B, 378 allocated ( 35 KB), 0 fragmented ( 0 KB) + 128 B, 1 allocated ( 0 KB), 30 fragmented ( 3 KB) + 192 B, 11 allocated ( 2 KB), 10 fragmented ( 1 KB) + 224 B, 1 allocated ( 0 KB), 17 fragmented ( 3 KB) + 288 B, 1 allocated ( 0 KB), 13 fragmented ( 3 KB) + 384 B, 1 allocated ( 0 KB), 9 fragmented ( 3 KB) + TOTAL, 393 allocated ( 38 KB), 79 fragmented ( 16 KB) +Free 4KB pages 0 (0 KB) +Large block count 0, total size 0 KB +Large fragments count 0, total size 0 KB +Large free 64KB pages 0, total size 0 KB +Big block count 1, total size 3907 KB + +Standard 1.00908173562059 +MT 0.538793103448276 +========== PAINT +TIMING Finish : 674.85 ms - 121.14 us (675.00 ms / 5571 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 5571 +TIMING Create : 38.67 ms - 317.78 ns (42.00 ms / 121697 ), min: 0.00 ns, max: 1.00 ms, nesting: 1 - 121697 diff --git a/benchmarks/LionBenchmark/lion.cpp b/benchmarks/LionBenchmark/lion.cpp index eb6d3cdd4..15895d722 100644 --- a/benchmarks/LionBenchmark/lion.cpp +++ b/benchmarks/LionBenchmark/lion.cpp @@ -173,6 +173,7 @@ Vector Lion() dword c = p.ReadNumber(16); color = Color(c >> 16, (c >> 8) & 255, c & 255); } + RDUMP(data.GetCount()); return data; } diff --git a/benchmarks/LionBenchmark/main.cpp b/benchmarks/LionBenchmark/main.cpp index ea7849aeb..f73c5523f 100644 --- a/benchmarks/LionBenchmark/main.cpp +++ b/benchmarks/LionBenchmark/main.cpp @@ -3,37 +3,58 @@ double tm[2]; struct MyApp : public TopWindow { + bool co = true; + + virtual void LeftDown(Point p, dword keyflags) + { + co = !co; + Refresh(); + } + virtual void Paint(Draw& w) { + RLOG("========== PAINT"); ImageBuffer ib(GetSize()); - BufferPainter sw(ib); -// sw.Co(); - sw.Clear(White()); - sw.Scale(2); - PaintLion(sw); + { + BufferPainter sw(ib); + sw.Co(co); + sw.Clear(White()); +// sw.Scale(2); +// sw.Opacity(0.98); + PaintLion(sw); + } w.DrawImage(0, 0, ib); w.DrawText(500, 0, Format("Standard %.4f", tm[0])); w.DrawText(500, 50, Format("Multithreaded %.4f", tm[1])); + w.DrawText(500, 100, Format("Standard / Multithreaded %.4f", tm[0] / tm[1])); + w.DrawText(500, 150, co ? "MT" : ""); } }; GUI_APP_MAIN { -#if 0 +#if 1 && !defined(_DEBUG) + RDUMP(MemoryUsedKb()); + PeakMemoryProfile(); ImageBuffer ib(1000, 1000); BufferPainter sw(ib); PaintLion(sw); for(int pass = 0; pass < 2; pass++) { int time0 = msecs(); int n = 0; - BufferPainter sw(ib); - sw.Scale(2); - sw.Opacity(0.3); while(msecs(time0) < 1000) { n++; + BufferPainter sw(ib); + sw.Co(pass); +// sw.Scale(2); +// sw.Opacity(0.3); PaintLion(sw); } tm[pass] = (double)msecs(time0) / n; } + RLOG("========================="); + RLOG(*PeakMemoryProfile()); + RLOG("Standard " << tm[0]); + RLOG("MT " << tm[1]); #endif MyApp().Run(); }