]> O.S.I.I.S - jp/crow.git/commitdiff
PerfTests improvments and command line args
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 13 Jan 2021 06:48:44 +0000 (07:48 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 13 Jan 2021 06:48:44 +0000 (07:48 +0100)
Crow/src/Interface.cs
Crow/src/Widgets/Label.cs
Crow/src/Widgets/TextRun.cs
Samples/PerfTests/Program.cs
Samples/PerfTests/Properties/launchSettings.json
Samples/common/ui/Interfaces/PerfLabels/0.crow [new file with mode: 0644]
Samples/common/ui/Interfaces/PerfLabels/1.crow [new file with mode: 0644]
Samples/common/ui/Interfaces/PerfLabels/2.crow [new file with mode: 0644]
Samples/common/ui/Interfaces/PerfLabels/labels.crow [new file with mode: 0644]

index daa76b257600e0799d83cfeb7619bebc1c2f4238..c54af96cd9f902d68042e6711dd0a19fd2e146b7 100644 (file)
@@ -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);
 
index 369d495ba752514ea0489a492b69b9d2fa8346cb..4d4f7f02ba597ddae65c50cbe000a7e57afc78ba 100644 (file)
@@ -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;
index 4c69e0e0761475b3b0b9acbdc0ddc1ad31e3a9aa..d118974fc6efb16d3eb4fe4d17a9600402d43f8c 100644 (file)
@@ -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 {
index 6b239e9ff952a0cee9b30ef0cd02e9c203101370..7a62fd8c96e27e1da7f5956d292c6f00389ff6aa 100644 (file)
@@ -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;
+
+                                       default:                                                
+                                               throw new Exception ();
+                                       }
+                               }
+                       } catch (Exception) {
+                               printHelp ();
+                               throw;
+                       }
 
-                       if (string.IsNullOrEmpty (_outDirectory)) {
+                       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) {
+            }
                }
        }
 }
index 2ffae32296ff24d3b5e2478290108b324b263be2..c5470b40578c925ddcd424cc123fae66406bdb31 100644 (file)
@@ -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 (file)
index 0000000..1430436
--- /dev/null
@@ -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 (file)
index 0000000..155e518
--- /dev/null
@@ -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 (file)
index 0000000..034518c
--- /dev/null
@@ -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 (file)
index 0000000..57c49ad
--- /dev/null
@@ -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>
+
+