From d1c982cdbf86904bfa9f7d93ea8b46ef8be291fb Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 18 Jun 2019 08:08:52 +0000 Subject: [PATCH] .benchmarks git-svn-id: svn://ultimatepp.org/upp/trunk@13413 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- benchmarks/CoLoop/CoLoop.cpp | 62 +++++++++++++++++++ benchmarks/CoLoop/CoLoop.upp | 9 +++ benchmarks/FontMetrics/FontMetrics.upp | 9 +++ benchmarks/FontMetrics/main.cpp | 84 ++++++++++++++++++++++++++ 4 files changed, 164 insertions(+) create mode 100644 benchmarks/CoLoop/CoLoop.cpp create mode 100644 benchmarks/CoLoop/CoLoop.upp create mode 100644 benchmarks/FontMetrics/FontMetrics.upp create mode 100644 benchmarks/FontMetrics/main.cpp diff --git a/benchmarks/CoLoop/CoLoop.cpp b/benchmarks/CoLoop/CoLoop.cpp new file mode 100644 index 000000000..e0cc26c66 --- /dev/null +++ b/benchmarks/CoLoop/CoLoop.cpp @@ -0,0 +1,62 @@ +#include + +using namespace Upp; + +Vector TestData() +{ + SeedRandom(0); + Vector data; + for(int i = 1; i < 100; i++) { + int n = 10 * (i + Random(i + 1)); + String h; + for(int i = 0; i < n; i++) + h << Random(99999) << ' '; + data.Add(h); + } + return data; +} + +int64 SumLine(const char *s) +{ + int64 sum = 0; + int64 n = 0; + while(*s) { + if(IsDigit(*s)) + n = 10 * n + *s - '0'; + else { + sum += n; + n = 0; + } + s++; + } + return sum + n; +} + +#ifdef _DEBUG +#define N 1 +#else +#define N 10000 +#endif + +int64 gsum; + +CONSOLE_APP_MAIN +{ + Vector data = TestData(); + + for(int i = 0; i < N; i++) { + RTIMING("ThreadLoop *"); + CoWork co; + int64 sum = 0; + std::atomic ii = 0; + co.Loop([&] { + int64 h = 0; + for(int i = ii++; i < data.GetCount(); i = ii++) + h += SumLine(data[i]); + CoWork::FinLock(); + sum += h; + }); + gsum = sum; + DUMP(gsum); + } +} diff --git a/benchmarks/CoLoop/CoLoop.upp b/benchmarks/CoLoop/CoLoop.upp new file mode 100644 index 000000000..2edd3eadc --- /dev/null +++ b/benchmarks/CoLoop/CoLoop.upp @@ -0,0 +1,9 @@ +uses + Core; + +file + CoLoop.cpp; + +mainconfig + "" = ""; + diff --git a/benchmarks/FontMetrics/FontMetrics.upp b/benchmarks/FontMetrics/FontMetrics.upp new file mode 100644 index 000000000..5872304d3 --- /dev/null +++ b/benchmarks/FontMetrics/FontMetrics.upp @@ -0,0 +1,9 @@ +uses + CtrlLib; + +file + main.cpp; + +mainconfig + "" = "GUI"; + diff --git a/benchmarks/FontMetrics/main.cpp b/benchmarks/FontMetrics/main.cpp new file mode 100644 index 000000000..768e7fb06 --- /dev/null +++ b/benchmarks/FontMetrics/main.cpp @@ -0,0 +1,84 @@ +#include + +using namespace Upp; + +const char *qtf = + "[ $$0,0#00000000000000000000000000000000:Default]" + "[*C@3+75 $$1,1#36268203433472503231438721581057:code]" + "[*/+117 $$2,0#07143242482611002448121871408047:title]" + "[@(128.0.255)2 $$3,0#65874547464505293575048467215454:QTF Chr]" + "[{_}%EN-US " + "[s0;= [*8 QTF]&]" + "[s0; &]" + "[s0; QTF is the native format of Ultimate`+`+ rich texts (formatted " + "texts).&]" + "[s0; &]" + "[s0; It is byte oriented format. Bytes with values 2`-31 are ignored. " + "Other are interpreted as characters or formatting commands.&]" + "[s0; &]" + "[s0; Letters ([@4 a]`-[@4 zA]`-[@4 Z]), numbers ([@4 0]`-[@4 9]), space (32) " + "and characters&]" + "[s0; &]" + "[s0; [*@4 . , ; ! ? % ( ) / < > #]&]" + "[s0; &]" + "[s0; and bytes greater than 127 are guaranteed to be never used as " + "command characters (not even in future versions of QTF). Other " + "characters should be prefixed with escape character `` (reverse " + "apostrophe). Group of characters can be escaped using byte 1. " + "Example:&]" + "[s0; &]" + "[s1; `\"`\1a`[x`]`\1`[`* bold`]`\"&]" + "[s0; &]" + "[s0; Byte 0 represents the end of input sequence.&]" + "[s0; &]" + "[s0; Dimension units of QTF are dots `- one dot is defined as 1/600 " + "of inch.&]" + "[s0; &]" + "[s0; Colors are described as either number [@(128.0.255) 0]`-[@(128.0.255) 9], " + "with meaning&]" + "[s0; &]" + "[ {{1000:1000:1000:1000:1000:1000:1000:1000:1000:1000<96;>96;f4; [s0;%- [* 0]]" + ":: [s0;%- [* 1]]" + ":: [s0;%- [* 2]]" + ":: [s0;%- [* 3]]" + ":: [s0;%- [* 4]]" + ":: [s0;%- [* 5]]" + ":: [s0;%- [* 6]]" + ":: [s0;%- [* 7]]" + ":: [s0;%- [* 8]]" + ":: [s0;%- [* 9]]" + "::l/0r/0t/0b/0@0 [s0; ]" + "::@1 [s0; ]" + "::@2 [s0; ]" + "::@3 [s0; ]" + "::@4 [s0; ]" + "::@5 [s0; ]" + "::@6 [s0; ]" + "::@7 [s0; ]" + "::@8 [s0; ]" + "::@9 [s0; ]" + "::l/25r/25t/15b/15@2 [s0;%- [1 Black]]" + ":: [s0; [1 LtGray]]" + ":: [s0; [1 White]]" + ":: [s0;%- [1 Red]]" + ":: [s0;%- [1 Green]]" + ":: [s0;%- [1 Blue]]" + ":: [s0;%- [1 LtRed]]" + ":: [s0;%- [1 WhiteGray]]" + ":: [s0;%- [1 LtCyan]]" + ":: [s0;%- [1 Yellow]]}}&]" + "[s0; &]" +; + +int sum; +RichText txt = ParseQTF(qtf); + +GUI_APP_MAIN +{ + RTIMING("Metrics"); + for(int i = 0; i < 1000; i++) { + RichText txt2 = clone(txt); + sum += txt2.GetHeight(1000); + } + BeepExclamation(); +}