public void Run() { var duration = Duration.TotalSeconds; var threadCount = ParallelRunner.ThreadCount; using (Writer.Section($"Test settings:")) { Writer.AppendMetric("Duration", duration * 1000, "ms"); Writer.AppendMetric("Thread count", threadCount, ""); Writer.AppendMetric("Unit size", UnitAllocator.UnitSize, "B"); } Writer.AppendLine(); var totalCount = 0L; for (var pass = 0; pass < PassCount; pass++) { var runner = ParallelRunner.New(i => new UnitAllocator(Duration)); var allocators = runner.Run(); totalCount = Math.Max(totalCount, allocators.Sum(a => a.AllocationCount)); } var totalSize = totalCount * UnitAllocator.UnitSize; var totalSizeWithOverhead = totalCount * (UnitAllocator.UnitSize + GarbageAllocator.ObjectSize); using (Writer.Section($"Allocation speed:")) { Writer.AppendMetric("Operations per second", totalCount / Sizes.Mega / duration, "M/s"); // Writer.AppendMetric("Bytes per second", totalSize / duration / Sizes.GB, "GB/s"); // Writer.AppendMetric("Bytes per second (incl. overhead)", totalSizeWithOverhead / duration / Sizes.GB, "GB/s"); } Writer.AppendLine(); }
public static void AppendHistogram(this IndentedTextWriter writer, string title, double[] data, string unit, string format = "0.####", double[] percentiles = null) { percentiles = percentiles ?? DefaultPercentiles; IndentedTextWriter AppendLine(string s) => writer.AppendLine(s); IndentedTextWriter AppendMetric(string name, double value) => writer.AppendMetric(name, value, unit); using (writer.Section($"{title}")) { if (data.Length == 0) { AppendLine("No data."); return; } AppendLine("Min .. Max:"); using (writer.Indent()) { AppendMetric("Min", data.Min()); AppendMetric("Avg", data.Average()); AppendMetric("Max", data.Max()); } if (percentiles.Length > 0) { AppendLine("Percentiles:"); using (writer.Indent()) { var maxIndex = data.Length - 1; foreach (var p in percentiles) { AppendMetric($"{p:#.##}%", data[(int)(maxIndex * p / 100)]); } } } } }
public static void Build() { //scale of sizes of views and fonts from original iosMath examples const double scale = 1.5; const double viewHeightExtraScale = 1.25; var sb = new StringBuilder(); string text; using (var client = new WebClient()) text = client.DownloadString( @"https://raw.githubusercontent.com/kostub/iosMath/master/iosMathExample/example/ViewController.m"); text = Regex.Split(text, @"\[self setHeight:\d+ forView:contentView\];|- \(void\)didReceiveMemoryWarning")[1]; var regex = new Regex(@"(?# )self\.(?<label>(?:demoLabels|labels)\[\d+\] = )\[self createMathLabel:(?# )@(?<latex>(?:""[^""]*?""\s+)+?)withHeight:(?<height>\d+)\];|(?# )self\.(?<colorTarget>(?:demoLabels|labels)\[\d+\])\.backgroundColor = (?# )\[UIColor colorWithHue:(?<hue>\d+(?:\.\d+)?) (?# )saturation:(?<saturation>\d+(?:\.\d+)?) (?# )brightness:(?<brightness>\d+(?:\.\d+)?) alpha:(?<alpha>\d+(?:\.\d+)?)\];|(?# )self\.(?<sizeTarget>(?:demoLabels|labels)\[\d+\])\.fontSize = (?# )(?<size>\d+(?:\.\d+)?);|(?# )self\.(?<alignTarget>(?:demoLabels|labels)\[\d+\])\.textAlignment = (?# )kMTTextAlignment(?<align>\w+);|(?# )self\.(?<insetsTarget>(?:demoLabels|labels)\[\d+\])\.contentInsets = (?# )UIEdgeInsetsMake\(?<insets>([\d\s,]+)\);|(?# )self\.(?<styleTarget>(?:demoLabels|labels)\[\d+\])\.labelMode = (?# )kMTMathUILabelMode(?<style>\w+);|(?# )\n\s+//(?<comment>.+)", RegexOptions.Compiled); var writer = new IndentedTextWriter(new StringWriter(sb), " ") { Indent = 0, NewLine = Environment.NewLine } .AppendLine("//Do not modify this file directly. Instead, modify this at") .AppendLine("//CSharpMath\\CSharpMath.Playground\\iosMathDemo\\ToFormsMoreExamples.cs and re-generate") .AppendLine("//this file by executing the method in that file in the CSharpMath.Utils project.") .AppendLine() .AppendLine("using CSharpMath.Atom;") .AppendLine("using CSharpMath.Rendering.FrontEnd;") .AppendLine("using System.Collections.Generic;") .AppendLine("using System.Collections.ObjectModel;") .AppendLine("using System.Linq;") .AppendLine("using Color = Xamarin.Forms.Color;") .AppendLine() .AppendLine("namespace CSharpMath.Forms.Example {") .Indent() .AppendLine("[System.Diagnostics.DebuggerNonUserCode, System.Runtime.CompilerServices.CompilerGenerated]") .AppendLine("public static class MoreExamples {") .Indent() .AppendLine("public static ReadOnlyCollection<MathView> Views { get; }") .AppendLine("static MoreExamples() {") .Indent() .AppendLine("var demoLabels = new Dictionary<byte, MathView>();") .AppendLine("var labels = new Dictionary<byte, MathView>();"); foreach (var m in regex.Matches(text).AsEnumerable()) { if (!string.IsNullOrEmpty(m.Groups["label"].Value)) { writer .Append(m.Groups["label"].Value) .AppendLine("new MathView {") .Indent() .Append("LaTeX = @\"") .Append(new StringBuilder(m.Groups["latex"].Value) .Replace("\\\n ", "\n ") .Replace("\n ", Environment.NewLine + ' ') .Replace(@"\\", @"\") .Replace("\"", "").ToString().TrimEnd()) .AppendLine("\",") .Append("HeightRequest = ") .Append(int.Parse(m.Groups["height"].Value, System.Globalization.NumberFormatInfo.InvariantInfo) * scale * viewHeightExtraScale) .AppendLine(",") .Append("FontSize = ") .Append(15 * scale) .AppendLine("f") .Unindent() .AppendLine("};"); } else if (!string.IsNullOrEmpty(m.Groups["colorTarget"].Value)) { writer.Append(m.Groups["colorTarget"].Value) .Append(".BackgroundColor = Color.FromHsla(") .Append(m.Groups["hue"].Value) .Append(", ") .Append(m.Groups["saturation"].Value) .Append(", ") .Append(m.Groups["brightness"].Value) .Append(", ") .Append(m.Groups["alpha"].Value) .AppendLine(");"); } else if (!string.IsNullOrEmpty(m.Groups["sizeTarget"].Value)) { writer.Append(m.Groups["sizeTarget"].Value) .Append(".FontSize = ") .Append(m.Groups["size"].Value) .AppendLine(";"); } else if (!string.IsNullOrEmpty(m.Groups["alignTarget"].Value)) { writer.Append(m.Groups["alignTarget"].Value) .Append(".TextAlignment = TextAlignment.") .Append(m.Groups["align"].Value) .AppendLine(";"); } else if (!string.IsNullOrEmpty(m.Groups["insetsTarget"].Value)) { writer.Append(m.Groups["insetsTarget"].Value) .Append(".Padding = new Thickness(") .Append(m.Groups["insets"].Value) .AppendLine(");"); } else if (!string.IsNullOrEmpty(m.Groups["styleTarget"].Value)) { writer.Append(m.Groups["styleTarget"].Value) .Append(".LineStyle = LineStyle.") .Append(m.Groups["style"].Value) .AppendLine(";"); } else if (!string.IsNullOrEmpty(m.Groups["comment"].Value)) { writer.AppendLine() .Append(@"// ") .AppendLine(m.Groups["comment"].Value); } } writer.AppendLine() .Append("Views = demoLabels.Concat(labels)") .AppendLine(".Select(p => p.Value).ToList().AsReadOnly();") .Unindent() .AppendLine("}") .Unindent() .AppendLine("}") .Unindent() .AppendLine("}") .Unindent(); if (writer.Indent != 0) { throw new InvalidOperationException("Indents are not balanced."); } File.WriteAllText(Paths.iosMathExamplesFile, sb.ToString()); writer.Dispose(); }
public void Run(Options options) { // Applying options if (!string.IsNullOrEmpty(options.GCLatencyMode)) { GCSettings.LatencyMode = Enum.Parse <GCLatencyMode>(options.GCLatencyMode); } if (options.Duration.HasValue) { BurnTester.DefaultDuration = TimeSpan.FromSeconds(options.Duration.Value); } BurnTester.DefaultMaxSize = ArgumentHelper.ParseRelativeValue( options.MaxSize, BurnTester.DefaultMaxSize, true); ParallelRunner.ThreadCount = (int)ArgumentHelper.ParseRelativeValue( options.ThreadCount, ParallelRunner.ThreadCount, true); var tests = options.Tests?.ToLowerInvariant() ?? ""; var ramSizeGb = HardwareInfo.GetRamSize() ?? 4; var staticSetSizeGb = 0; if (!string.IsNullOrEmpty(options.StaticSetSize)) { tests += "b"; staticSetSizeGb = (int)ArgumentHelper.ParseRelativeValue(options.StaticSetSize, ramSizeGb, true); } var outputMode = options.OutputMode ?? "f"; if (outputMode == "f") { // Dumping environment info Writer.AppendValue("Launch parameters", string.Join(" ", Environment.GetCommandLineArgs().Skip(1))); using (Writer.Section("Software:")) { Writer.AppendValue("Runtime", ".NET Core"); using (Writer.Indent()) { Writer.AppendValue("Version", RuntimeInformation.FrameworkDescription); Writer.AppendValue("GC mode", GCInfo.GetGCMode()); } Writer.AppendValue("OS", $"{RuntimeInformation.OSDescription.Trim()} ({RuntimeInformation.OSArchitecture})"); } using (Writer.Section("Hardware:")) { var coreCountAddon = ParallelRunner.ThreadCount != Environment.ProcessorCount ? $", {ParallelRunner.ThreadCount} used by test" : ""; Writer.AppendValue("CPU", HardwareInfo.GetCpuModelName()); Writer.AppendValue("CPU core count", $"{Environment.ProcessorCount}{coreCountAddon}"); Writer.AppendValue("RAM size", $"{ramSizeGb:N0} GB"); } Writer.AppendLine(); } RunWarmup(); if (tests == "") { RunSpeedTest(); RunBurnTest("--- Stateless server (no static set) ---", 0); RunBurnTest("--- Worker / typical server (static set = 20% RAM) ---", (long)(ramSizeGb * Sizes.GB / 5)); RunBurnTest("--- Caching / compute server (static set = 50% RAM) ---", (long)(ramSizeGb * Sizes.GB / 2)); return; } if (tests.Contains("a")) { RunSpeedTest(); } if (tests.Contains("b")) { var title = $"--- Static set = {staticSetSizeGb} GB ({staticSetSizeGb * 100.0 / ramSizeGb:0.##} % RAM) ---"; RunBurnTest(title, (long)(staticSetSizeGb * Sizes.GB)); } }
public static IndentedTextWriter AppendValue(this IndentedTextWriter writer, string name, string value) { var formattedName = string.Format($"{{0,-{Math.Max(0, 1 + ValueColumnIndex - writer.Indent * IndentSize)}}}", name + ":"); return(writer.AppendLine($"{formattedName} {value}")); }