using System.Collections.Generic; using Azimuth; namespace Glass.PerformanceTests { public static class Scenarios { public const int Width = 300; public const int NarrowWidth = 60; public const int VisibleLines = 3; public static string NameFor(string textName, string constraint, SpriteFontDefinition font, Operation operation) { return $"{textName}, {constraint}, {SampleFonts.Describe(font)}: {operation}"; } public static void AddEach(List scenarios, string textName, string constraint, Workload workload, params Operation[] operations) { foreach (Operation operation in operations) { scenarios.Add(new Scenario(NameFor(textName, constraint, workload.Font, operation), workload, operation)); } } /// /// Every scenario, in a fixed order so an index names the same one in every process. /// public static List BuildAll() { SpriteFontDefinition font = SampleFonts.Philosopher18; string wide = $"{Width}px"; var returnMe = new List(); AddEach(returnMe, "label", "unbounded", new Workload(font, Texts.Label), Operation.MeasureWidth, Operation.CalculateSize); AddEach(returnMe, "label", wide, new Workload(font, Texts.Label, maxWidth: Width), Operation.PlaceGlyphs); AddEach(returnMe, "tiny label", "unbounded", new Workload(font, Texts.TinyLabel), Operation.MeasureWidth, Operation.CalculateSize); AddEach(returnMe, "CJK label", "unbounded", new Workload(font, Texts.CjkLabel), Operation.MeasureWidth, Operation.CalculateSize); AddEach(returnMe, "1 KB prose", wide, new Workload(font, Texts.Prose, maxWidth: Width), Operation.CalculateSize, Operation.PlaceGlyphs); AddEach(returnMe, "1 KB prose", wide, new Workload(SampleFonts.LiberationSans16, Texts.Prose, maxWidth: Width), Operation.CalculateSize, Operation.PlaceGlyphs); AddEach(returnMe, "1 KB prose", $"{NarrowWidth}px", new Workload(font, Texts.Prose, maxWidth: NarrowWidth), Operation.CalculateSize, Operation.PlaceGlyphs); Scalar visibleHeight = VisibleLines * font.LineHeight; AddEach(returnMe, "1 KB prose", $"{Width}px x {VisibleLines} lines, ellipsis", new Workload(font, Texts.Prose, maxWidth: Width, maxHeight: visibleHeight, overflow: TextOverflow.Ellipsis), Operation.CalculateSize, Operation.PlaceGlyphs); AddEach(returnMe, "20 KB document", wide, new Workload(font, Texts.Document, maxWidth: Width), Operation.CalculateSize, Operation.PlaceGlyphs); AddEach(returnMe, "512-char hex run", "unbounded", new Workload(font, Texts.HexRun), Operation.MeasureWidth); AddEach(returnMe, "512-char hex run", wide, new Workload(font, Texts.HexRun, maxWidth: Width), Operation.CalculateSize, Operation.PlaceGlyphs); AddEach(returnMe, "CJK prose", "unbounded", new Workload(font, Texts.CjkProse), Operation.MeasureWidth); AddEach(returnMe, "CJK prose", wide, new Workload(font, Texts.CjkProse, maxWidth: Width), Operation.CalculateSize, Operation.PlaceGlyphs); AddEach(returnMe, "1 KB numbers", wide, new Workload(font, Texts.Numbers, maxWidth: Width), Operation.CalculateSize, Operation.PlaceGlyphs); return returnMe; } } }