aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2021-01-13 07:48:44 +0100
committerj-p <jp_bruyere@hotmail.com>2021-02-06 20:28:02 +0100
commitd3b306830e774c1998793fe28eb4d53e39a7e665 (patch)
treec0027498e357e5d8eea10df45e53ef5da7d5f1ef
parent3eb112aa682802b9d6cc71c9d243a44ceeb9d7a1 (diff)
PerfTests improvments and command line args
-rw-r--r--Crow/src/Interface.cs4
-rw-r--r--Crow/src/Widgets/Label.cs2
-rw-r--r--Crow/src/Widgets/TextRun.cs4
-rw-r--r--Samples/PerfTests/Program.cs145
-rw-r--r--Samples/PerfTests/Properties/launchSettings.json2
-rw-r--r--Samples/common/ui/Interfaces/PerfLabels/0.crow3
-rw-r--r--Samples/common/ui/Interfaces/PerfLabels/1.crow3
-rw-r--r--Samples/common/ui/Interfaces/PerfLabels/2.crow3
-rw-r--r--Samples/common/ui/Interfaces/PerfLabels/labels.crow53
9 files changed, 182 insertions, 37 deletions
diff --git a/Crow/src/Interface.cs b/Crow/src/Interface.cs
index daa76b25..c54af96c 100644
--- a/Crow/src/Interface.cs
+++ b/Crow/src/Interface.cs
@@ -141,7 +141,7 @@ namespace Crow
Glfw3.SetWindowSizeCallback (hWin, HandleWindowSizeDelegate);
}
- void initSurface ()
+ protected void initSurface ()
{
Glfw3.Init ();
@@ -251,9 +251,11 @@ namespace Crow
while (!Glfw3.WindowShouldClose (hWin)) {
Glfw3.PollEvents ();
+ UpdateFrame ();
Thread.Sleep(1);
}
}
+ public virtual void UpdateFrame () { }
public virtual void Quit () => Glfw3.SetWindowShouldClose (hWin, 1);
diff --git a/Crow/src/Widgets/Label.cs b/Crow/src/Widgets/Label.cs
index 369d495b..4d4f7f02 100644
--- a/Crow/src/Widgets/Label.cs
+++ b/Crow/src/Widgets/Label.cs
@@ -340,7 +340,7 @@ namespace Crow {
bool lineBreak = false;
int start = 0, end = 0;
for (int i = 0; i < _text.Length; i++) {
- if (_text[i] == '\r' || _text[i] == '\n') {
+ if (_text[i].IsAnyLineBreakCharacter()) {
if (lineBreak)
continue;
lineBreak = true;
diff --git a/Crow/src/Widgets/TextRun.cs b/Crow/src/Widgets/TextRun.cs
index 4c69e0e0..d118974f 100644
--- a/Crow/src/Widgets/TextRun.cs
+++ b/Crow/src/Widgets/TextRun.cs
@@ -19,8 +19,6 @@ namespace Crow
public TextRun (Interface iface, string style = null) : base (iface, style) { }
#endregion
- //TODO:change protected to private
-
#region private and protected fields
protected string _text = "label";
Alignment _textAlignment = Alignment.Left;
@@ -34,8 +32,6 @@ namespace Crow
protected FontExtents fe;
protected TextExtents te;
#endregion
-
-
[DefaultValue (Alignment.Left)]
public Alignment TextAlignment {
diff --git a/Samples/PerfTests/Program.cs b/Samples/PerfTests/Program.cs
index 6b239e9f..7a62fd8c 100644
--- a/Samples/PerfTests/Program.cs
+++ b/Samples/PerfTests/Program.cs
@@ -11,32 +11,98 @@ namespace PerfTests
{
class TestInterface : Interface
{
- readonly int count;
+ readonly int count = 1, updateCycles = 0;
readonly bool miliseconds = false;
- readonly bool resetStylesAndTemplates = true;
- readonly string outDirectory;
+ readonly bool resetItors = false;
+ readonly bool screenOutput = false;
+ readonly string inDirectory = "Interfaces";//directory to test
- Stream outStream;
+
+ Stream outStream;
TextWriter writer;
bool logToDisk => writer != null;
void writeHeader (TextWriter txtWriter) {
- txtWriter.WriteLine ($"Crow perf test ({clientRectangle.Width} X {clientRectangle.Height}), repeat count = {count}, reset style and templates = {resetStylesAndTemplates}");
+ txtWriter.WriteLine ($"Crow perf test ({clientRectangle.Width} X {clientRectangle.Height}), repeat count = {count}, reset style and templates = {resetItors}");
txtWriter.WriteLine ($"git:{ThisAssembly.Git.Commit} {ThisAssembly.Git.Branch} {ThisAssembly.Git.SemVer.Major}.{ThisAssembly.Git.SemVer.Minor}.{ThisAssembly.Git.SemVer.Patch} {ThisAssembly.Git.SemVer.Label}");
}
- public TestInterface (int count, string _outDirectory = "", int width = 800, int height = 600)
+
+ void printHelp () {
+ Console.WriteLine ("Usage: PerfTests.exe [options]\n");
+ Console.WriteLine ("-o,--output:\n\tWrite results to output directory, if omited, results are printed to screen.");
+ Console.WriteLine ("-i,--input:\n\tInput directory to search recursively for '.crow' file to test.");
+ Console.WriteLine ("-w,--width:\n\toutput surface width, not displayed on screen.");
+ Console.WriteLine ("-h,--height:\n\toutput surface height, not displayed on screen.");
+ Console.WriteLine ("-c,--count:\n\trepeat each test 'c' times.");
+ Console.WriteLine ("-m,--millisec:\n\tenable measure time in milisecond, if omitted measure in ticks.");
+ Console.WriteLine ("-r,--reset:\n\tenable clear iterators after each test file.");
+ Console.WriteLine ("-u,--update:\n\tmeasure 'n' update cycle with DateTime.Now string notified.");
+ Console.WriteLine ("-s,--screen:\n\tenable output to screen.");
+ }
+
+ public TestInterface (string[] args, int width = 800, int height = 600)
: base (width, height, false, false)
{
- this.count = count;
+ string outDir = null;
+
+ int i = 0;
+ try {
+ while (i < args.Length) {
+ switch (args[i++]) {
+ case "-o":
+ case "--output":
+ outDir = args[i++];
+ break;
+ case "-i":
+ case "--input":
+ inDirectory = args[i++];
+ break;
+ case "-c":
+ case "--count":
+ count = int.Parse (args[i++]);
+ break;
+ case "-w":
+ case "--width":
+ clientRectangle.Width = int.Parse (args[i++]);
+ break;
+ case "-h":
+ case "--height":
+ clientRectangle.Height = int.Parse (args[i++]);
+ break;
+ case "-m":
+ case "--millisec":
+ miliseconds = true;
+ break;
+ case "-r":
+ case "--reset":
+ resetItors = true;
+ break;
+ case "-u":
+ case "--update":
+ updateCycles = int.Parse (args[i++]);
+ break;
+ case "-s":
+ case "--screen":
+ screenOutput = true;
+ break;
- if (string.IsNullOrEmpty (_outDirectory)) {
+ default:
+ throw new Exception ();
+ }
+ }
+ } catch (Exception) {
+ printHelp ();
+ throw;
+ }
+
+ if (string.IsNullOrEmpty (outDir)) {
writeHeader (Console.Out);
Console.WriteLine (new string ('-', 100));
Console.WriteLine ($"{" Path",-50}| Min | Mean | Max | Alloc(kb)| Lost(Kb) |");
} else {
- string dirName = Path.IsPathRooted (_outDirectory) ? _outDirectory :
- Path.Combine (Directory.GetCurrentDirectory (), _outDirectory);
+ string dirName = Path.IsPathRooted (outDir) ? outDir :
+ Path.Combine (Directory.GetCurrentDirectory (), outDir);
if (!Directory.Exists (dirName))
Directory.CreateDirectory (dirName);
@@ -47,11 +113,23 @@ namespace PerfTests
writer.WriteLine ("Path;Min;Mean;Max;Allocated;LostMem");
}
- surf = new Crow.Cairo.ImageSurface (Crow.Cairo.Format.Argb32, ClientRectangle.Width, ClientRectangle.Height);
+ if (screenOutput)
+ initSurface ();
+ else
+ surf = new Crow.Cairo.ImageSurface (Crow.Cairo.Format.Argb32, ClientRectangle.Width, ClientRectangle.Height);
Init ();
}
- protected override void Dispose (bool disposing) {
+ public void PerformTests () {
+ string dirName = Path.IsPathRooted (inDirectory) ? inDirectory :
+ Path.Combine (Directory.GetCurrentDirectory (), inDirectory);
+ if (!Directory.Exists (dirName))
+ throw new FileNotFoundException ("Input directory not found: " + dirName);
+
+ testDir (dirName);
+ }
+
+ protected override void Dispose (bool disposing) {
base.Dispose (disposing);
if (logToDisk) {
@@ -70,17 +148,31 @@ namespace PerfTests
Stopwatch sw = new Stopwatch ();
for (int i = 0; i < count; i++) {
- sw.Restart ();
+ if (updateCycles == 0) {
+ sw.Restart ();//dont measure load time when measuring updates
+ Load (path);
+ }else
+ Load (path).DataSource = this;
- Load (path);
+ Update ();
while (LayoutingQueue.Count > 0)
Update ();
+ if (updateCycles > 0) {
+ sw.Restart ();
+ for (int j = 0; j < updateCycles; j++) {
+ NotifyValueChanged ("elapsed", sw.ElapsedTicks);
+ Update ();
+ while (LayoutingQueue.Count > 0)
+ Update ();
+ }
+ }
+
sw.Stop ();
ClearInterface ();
- if (resetStylesAndTemplates) {
+ if (resetItors) {
//this.Styling.Clear ();
//this.StylingConstants.Clear ();
this.Instantiators.Clear ();
@@ -108,10 +200,9 @@ namespace PerfTests
return total / count;
}
-
void testDir (string dirPath, int level = 0)
{
- string label = $"{new string (' ', level * 4)}- {dirPath}";
+ string label = $"{new string (' ', level * 4)}- {Path.GetFileName (dirPath)}";
if (!logToDisk)
Console.WriteLine (label, -50);
level++;
@@ -143,27 +234,21 @@ namespace PerfTests
} else {
Console.WriteLine ($"{label,-50}");
Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine ($"\t\t{ex.Message}");
+ Console.WriteLine ($"\t\t{ex.ToString()}");
Console.ResetColor ();
}
}
}
}
-
public static void Main (string [] args)
{
- int count = 10;
- string outDir = "";
-
- if (args.Length > 0 && int.TryParse (args[0], out int c))
- count = c;
- if (args.Length > 1)
- outDir = args[1];
-
- using (TestInterface iface = new TestInterface (count, outDir)) {
- iface.testDir (@"Interfaces");
- }
+ try {
+ using (TestInterface iface = new TestInterface (args)) {
+ iface.PerformTests ();
+ }
+ } catch (Exception) {
+ }
}
}
}
diff --git a/Samples/PerfTests/Properties/launchSettings.json b/Samples/PerfTests/Properties/launchSettings.json
index 2ffae322..c5470b40 100644
--- a/Samples/PerfTests/Properties/launchSettings.json
+++ b/Samples/PerfTests/Properties/launchSettings.json
@@ -2,7 +2,7 @@
"profiles": {
"PerfTests": {
"commandName": "Project",
- "commandLineArgs": "1"
+ "commandLineArgs": "-c 5 -u 99 -s -i Interfaces/PerfLabels"
}
}
} \ No newline at end of file
diff --git a/Samples/common/ui/Interfaces/PerfLabels/0.crow b/Samples/common/ui/Interfaces/PerfLabels/0.crow
new file mode 100644
index 00000000..14304360
--- /dev/null
+++ b/Samples/common/ui/Interfaces/PerfLabels/0.crow
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<Label Text="no update in this file"/>
+
diff --git a/Samples/common/ui/Interfaces/PerfLabels/1.crow b/Samples/common/ui/Interfaces/PerfLabels/1.crow
new file mode 100644
index 00000000..155e5188
--- /dev/null
+++ b/Samples/common/ui/Interfaces/PerfLabels/1.crow
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<TextRun Text="{elapsed}" Fit="true" Background="Onyx"/>
+
diff --git a/Samples/common/ui/Interfaces/PerfLabels/2.crow b/Samples/common/ui/Interfaces/PerfLabels/2.crow
new file mode 100644
index 00000000..034518cb
--- /dev/null
+++ b/Samples/common/ui/Interfaces/PerfLabels/2.crow
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<Label Text="{elapsed}" Fit="true" Background="Onyx"/>
+
diff --git a/Samples/common/ui/Interfaces/PerfLabels/labels.crow b/Samples/common/ui/Interfaces/PerfLabels/labels.crow
new file mode 100644
index 00000000..57c49ad5
--- /dev/null
+++ b/Samples/common/ui/Interfaces/PerfLabels/labels.crow
@@ -0,0 +1,53 @@
+<?xml version="1.0"?>
+<HorizontalStack>
+ <VerticalStack Width="20%" Height="Fit">
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ </VerticalStack>
+ <VerticalStack Width="20%" Height="Fit">
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ </VerticalStack>
+ <VerticalStack Width="20%" Height="Fit">
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ </VerticalStack>
+ <VerticalStack Width="20%" Height="Fit">
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ <Label Text="{elapsed}" />
+ </VerticalStack>
+</HorizontalStack>
+
+