From: 최종헌/MDE Lab(SR)/삼성전자 Date: Wed, 29 May 2024 08:18:59 +0000 (+0900) Subject: Add TizenDotnetBenchmark Test App (#554) X-Git-Tag: accepted/tizen/unified/20240621.010434~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=66bac3770a4a37862534a106f3d469da3bb55abb;p=platform%2Fcore%2Fdotnet%2Flauncher.git Add TizenDotnetBenchmark Test App (#554) --- diff --git a/tests/Benchmark/TizenBenchmark/Directory.Build.targets b/tests/Benchmark/TizenBenchmark/Directory.Build.targets new file mode 100644 index 0000000..67fcf5d --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Directory.Build.targets @@ -0,0 +1,21 @@ + + + + + + + + $([System.IO.Path]::GetDirectoryName($(MSBuildProjectDirectory))) + + + + + + diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroArguments.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroArguments.cs new file mode 100644 index 0000000..88c726f --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroArguments.cs @@ -0,0 +1,29 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + public class IntroArguments + { + [Params(true, false)] // Arguments can be combined with Params + public bool AddExtra5Milliseconds; + + [Benchmark] + [Arguments(100, 10)] + [Arguments(100, 20)] + [Arguments(200, 10)] + [Arguments(200, 20)] + public void Benchmark(int a, int b) + { + if (AddExtra5Milliseconds) + Thread.Sleep(a + b + 5); + else + Thread.Sleep(a + b); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroArgumentsSource.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroArgumentsSource.cs new file mode 100644 index 0000000..4470f7f --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroArgumentsSource.cs @@ -0,0 +1,35 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + public class IntroArgumentsSource + { + [Benchmark] + [ArgumentsSource(nameof(Numbers))] + public double ManyArguments(double x, double y) => Math.Pow(x, y); + + public IEnumerable Numbers() // for multiple arguments it's an IEnumerable of array of objects (object[]) + { + yield return new object[] { 1.0, 1.0 }; + yield return new object[] { 2.0, 2.0 }; + yield return new object[] { 4.0, 4.0 }; + yield return new object[] { 10.0, 10.0 }; + } + + [Benchmark] + [ArgumentsSource(nameof(TimeSpans))] + public void SingleArgument(TimeSpan time) => Thread.Sleep(time); + + public IEnumerable TimeSpans() // for single argument it's an IEnumerable of objects (object) + { + yield return TimeSpan.FromMilliseconds(10); + yield return TimeSpan.FromMilliseconds(100); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroArrayParam.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroArrayParam.cs new file mode 100644 index 0000000..ead0b43 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroArrayParam.cs @@ -0,0 +1,36 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + public class IntroArrayParam + { + [Benchmark] + [ArgumentsSource(nameof(Data))] + public int ArrayIndexOf(int[] array, int value) + => Array.IndexOf(array, value); + + [Benchmark] + [ArgumentsSource(nameof(Data))] + public int ManualIndexOf(int[] array, int value) + { + for (int i = 0; i < array.Length; i++) + if (array[i] == value) + return i; + + return -1; + } + + public IEnumerable Data() + { + yield return new object[] { new int[] { 1, 2, 3 }, 4 }; + yield return new object[] { Enumerable.Range(0, 100).ToArray(), 4 }; + yield return new object[] { Enumerable.Range(0, 100).ToArray(), 101 }; + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroBasic.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroBasic.cs new file mode 100644 index 0000000..6a75b4e --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroBasic.cs @@ -0,0 +1,22 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + // It is very easy to use BenchmarkDotNet. You should just create a class + public class IntroBasic + { + // And define a method with the Benchmark attribute + [Benchmark] + public void Sleep() => Thread.Sleep(10); + + // You can write a description for your method. + [Benchmark(Description = "Thread.Sleep(10)")] + public void SleepWithDescription() => Thread.Sleep(10); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroBenchmarkBaseline.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroBenchmarkBaseline.cs new file mode 100644 index 0000000..9e9c4a2 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroBenchmarkBaseline.cs @@ -0,0 +1,22 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + public class IntroBenchmarkBaseline + { + [Benchmark] + public void Time50() => Thread.Sleep(50); + + [Benchmark(Baseline = true)] + public void Time100() => Thread.Sleep(100); + + [Benchmark] + public void Time150() => Thread.Sleep(150); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroCategories.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroCategories.cs new file mode 100644 index 0000000..2224716 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroCategories.cs @@ -0,0 +1,33 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [DryJob] + [CategoriesColumn] + [BenchmarkCategory("Awesome")] + [AnyCategoriesFilter("A", "1")] + public class IntroCategories + { + [Benchmark] + [BenchmarkCategory("A", "1")] + public void A1() => Thread.Sleep(10); // Will be benchmarked + + [Benchmark] + [BenchmarkCategory("A", "2")] + public void A2() => Thread.Sleep(10); // Will be benchmarked + + [Benchmark] + [BenchmarkCategory("B", "1")] + public void B1() => Thread.Sleep(10); // Will be benchmarked + + [Benchmark] + [BenchmarkCategory("B", "2")] + public void B2() => Thread.Sleep(10); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroCategoryBaseline.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroCategoryBaseline.cs new file mode 100644 index 0000000..9223ad4 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroCategoryBaseline.cs @@ -0,0 +1,28 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] + [CategoriesColumn] + public class IntroCategoryBaseline + { + [BenchmarkCategory("Fast"), Benchmark(Baseline = true)] + public void Time50() => Thread.Sleep(50); + + [BenchmarkCategory("Fast"), Benchmark] + public void Time100() => Thread.Sleep(100); + + [BenchmarkCategory("Slow"), Benchmark(Baseline = true)] + public void Time550() => Thread.Sleep(550); + + [BenchmarkCategory("Slow"), Benchmark] + public void Time600() => Thread.Sleep(600); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroCategoryDiscoverer.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroCategoryDiscoverer.cs new file mode 100644 index 0000000..c45c6e8 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroCategoryDiscoverer.cs @@ -0,0 +1,50 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Running; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [DryJob] + [CategoriesColumn] + [CustomCategoryDiscoverer] + public class IntroCategoryDiscoverer + { + private class CustomCategoryDiscoverer : DefaultCategoryDiscoverer + { + public override string[] GetCategories(MethodInfo method) + { + var categories = new List(); + categories.AddRange(base.GetCategories(method)); + categories.Add("All"); + categories.Add(method.Name.Substring(0, 1)); + return categories.ToArray(); + } + } + + [AttributeUsage(AttributeTargets.Class)] + private class CustomCategoryDiscovererAttribute : Attribute, IConfigSource + { + public CustomCategoryDiscovererAttribute() + { + Config = ManualConfig.CreateEmpty() + .WithCategoryDiscoverer(new CustomCategoryDiscoverer()); + } + + public IConfig Config { get; } + } + + + [Benchmark] + public void Foo() { } + + [Benchmark] + public void Bar() { } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroColdStart.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroColdStart.cs new file mode 100644 index 0000000..9be7b9a --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroColdStart.cs @@ -0,0 +1,31 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Engines; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [SimpleJob(RunStrategy.ColdStart, iterationCount: 5)] + [MinColumn, MaxColumn, MeanColumn, MedianColumn] + public class IntroColdStart + { + private bool firstCall; + + [Benchmark] + public void Foo() + { + if (firstCall == false) + { + firstCall = true; + Console.WriteLine("// First call"); + Thread.Sleep(1000); + } + else + Thread.Sleep(10); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroComparableComplexParam.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroComparableComplexParam.cs new file mode 100644 index 0000000..7ed9e62 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroComparableComplexParam.cs @@ -0,0 +1,41 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + public class IntroComparableComplexParam + { + [ParamsSource(nameof(ValuesForA))] + public ComplexParam? A { get; set; } + + public IEnumerable ValuesForA => new[] { new ComplexParam(1, "First"), new ComplexParam(2, "Second") }; + + [Benchmark] + public object? Benchmark() => A; + + // Only non generic IComparable is required to provide custom order behavior, but implementing IComparable<> too is customary. + public class ComplexParam : IComparable, IComparable + { + public ComplexParam(int value, string name) + { + Value = value; + Name = name; + } + + public int Value { get; set; } + + public string Name { get; set; } + + public override string ToString() => Name; + + public int CompareTo(ComplexParam? other) => other == null ? 1 : Value.CompareTo(other.Value); + + public int CompareTo(object obj) => obj is ComplexParam other ? CompareTo(other) : throw new ArgumentException(); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroConfigSource.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroConfigSource.cs new file mode 100644 index 0000000..9c67de5 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroConfigSource.cs @@ -0,0 +1,39 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [MyConfigSource(Jit.LegacyJit, Jit.RyuJit)] + public class IntroConfigSource + { + /// + /// Dry-x64 jobs for specific jits + /// + private class MyConfigSourceAttribute : Attribute, IConfigSource + { + public IConfig Config { get; } + + public MyConfigSourceAttribute(params Jit[] jits) + { + var jobs = jits + .Select(jit => new Job(Job.Dry) { Environment = { Jit = jit, Platform = Platform.X64 } }) + .ToArray(); + Config = ManualConfig.CreateEmpty().AddJob(jobs); + } + } + + [Benchmark] + public void Foo() + { + Thread.Sleep(10); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroConfigUnion.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroConfigUnion.cs new file mode 100644 index 0000000..4846b7c --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroConfigUnion.cs @@ -0,0 +1,40 @@ +using BenchmarkDotNet.Analysers; +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Columns; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Exporters.Csv; +using BenchmarkDotNet.Exporters; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Loggers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [Config(typeof(Config))] + public class IntroConfigUnion + { + private class Config : ManualConfig + { + public Config() + { + AddJob(Job.Dry); + AddLogger(ConsoleLogger.Default); + AddColumn(TargetMethodColumn.Method, StatisticColumn.Max); + AddExporter(RPlotExporter.Default, CsvExporter.Default); + AddAnalyser(EnvironmentAnalyser.Default); + UnionRule = ConfigUnionRule.AlwaysUseLocal; + } + } + + [Benchmark] + public void Foo() + { + Thread.Sleep(10); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroCustomMono.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroCustomMono.cs new file mode 100644 index 0000000..fd326a1 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroCustomMono.cs @@ -0,0 +1,101 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Running; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + // *** Attribute Style *** + + [MonoJob("Mono x64", @"C:\Program Files\Mono\bin\mono.exe")] + [MonoJob("Mono x86", @"C:\Program Files (x86)\Mono\bin\mono.exe")] + public class IntroCustomMono + { + [Benchmark] + public void Foo() + { + // Benchmark body + } + } + + // *** Object Style *** + + [Config(typeof(Config))] + public class IntroCustomMonoObjectStyle + { + private class Config : ManualConfig + { + public Config() + { + AddJob(Job.ShortRun.WithRuntime(new MonoRuntime( + "Mono x64", @"C:\Program Files\Mono\bin\mono.exe"))); + AddJob(Job.ShortRun.WithRuntime(new MonoRuntime( + "Mono x86", @"C:\Program Files (x86)\Mono\bin\mono.exe"))); + } + } + + [Benchmark] + public void Foo() + { + // Benchmark body + } + } + + // ** Object Style, Using AOT ** + + [Config(typeof(Config))] + public class IntroCustomMonoObjectStyleAot + { + private class Config : ManualConfig + { + public void AddMono(string name, string mono_top_dir) + { + var aot_compile_args = "--aot=llvm"; + var mono_bcl = $@"{mono_top_dir}\lib\mono\4.5"; + var mono_bin = $@"{mono_top_dir}\bin\mono.exe"; + AddJob(Job.ShortRun.WithRuntime(new MonoRuntime( + name, mono_bin, aot_compile_args, mono_bcl))); + } + + public Config() + { + AddMono("Mono x64", @"C:\Program Files\Mono"); + AddMono("Mono x86", @"C:\Program Files (x86)\Mono"); + } + } + + [Benchmark] + public void Foo() + { + // Benchmark body + } + } + + // *** Fluent Config *** + + public class IntroCustomMonoFluentConfig + { + public static void Run() + { + BenchmarkRunner.Run(ManualConfig + .CreateMinimumViable() + .AddJob(Job.ShortRun.WithRuntime(new MonoRuntime( + "Mono x64", @"C:\Program Files\Mono\bin\mono.exe"))) + .AddJob(Job.ShortRun.WithRuntime(new MonoRuntime( + "Mono x86", @"C:\Program Files (x86)\Mono\bin\mono.exe")))); + } + + [Benchmark] + public void Foo() + { + // Benchmark body + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroCustomMonoArguments.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroCustomMonoArguments.cs new file mode 100644 index 0000000..2e2ee32 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroCustomMonoArguments.cs @@ -0,0 +1,47 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [Config(typeof(ConfigWithCustomArguments))] + public class IntroCustomMonoArguments + { + public class ConfigWithCustomArguments : ManualConfig + { + public ConfigWithCustomArguments() + { + // --optimize=MODE , -O=mode + // MODE is a comma separated list of optimizations. They also allow + // optimizations to be turned off by prefixing the optimization + // name with a minus sign. + + AddJob(Job.Default + .WithRuntime(MonoRuntime.Default) + .WithArguments(new[] { new MonoArgument("--optimize=inline") }) + .WithId("Inlining enabled")); + AddJob(Job.Default + .WithRuntime(MonoRuntime.Default) + .WithArguments(new[] { new MonoArgument("--optimize=-inline") }) + .WithId("Inlining disabled")); + } + } + + [Benchmark] + public void Sample() + { + ShouldGetInlined(); ShouldGetInlined(); ShouldGetInlined(); + ShouldGetInlined(); ShouldGetInlined(); ShouldGetInlined(); + ShouldGetInlined(); ShouldGetInlined(); ShouldGetInlined(); + } + + private void ShouldGetInlined() { } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroDeferredExecution.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroDeferredExecution.cs new file mode 100644 index 0000000..b425ac8 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroDeferredExecution.cs @@ -0,0 +1,35 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Engines; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + public class IntroDeferredExecution + { + private readonly int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + private readonly Consumer consumer = new Consumer(); + + /// + /// this benchmark returns a deferred LINQ query which is NOT executed + /// so the benchmark measures the cost of creating the query, not the actual execution + /// this is WRONG + /// You can read more about LINQ and Deferred Execution here + /// + /// deferred LINQ query + [Benchmark] + public IEnumerable Wrong() => from number in numbers orderby number descending select number; + + /// + /// this benchmark uses .Consume extension method which executes given deferred query and consumes its result + /// so the benchmark measures the cost of creating the query and executing it + /// + [Benchmark] + public void Ok() => (from number in numbers orderby number descending select number).Consume(consumer); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroDisassembly.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroDisassembly.cs new file mode 100644 index 0000000..90eca54 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroDisassembly.cs @@ -0,0 +1,39 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Diagnosers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [DisassemblyDiagnoser(printInstructionAddresses: true, syntax: DisassemblySyntax.Masm)] + public class IntroDisassembly + { + private int[] field = Enumerable.Range(0, 100).ToArray(); + + [Benchmark] + public int SumLocal() + { + var local = field; // we use local variable that points to the field + + int sum = 0; + for (int i = 0; i < local.Length; i++) + sum += local[i]; + + return sum; + } + + [Benchmark] + public int SumField() + { + int sum = 0; + for (int i = 0; i < field.Length; i++) + sum += field[i]; + + return sum; + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroDisassemblyAllJits.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroDisassemblyAllJits.cs new file mode 100644 index 0000000..deccfdd --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroDisassemblyAllJits.cs @@ -0,0 +1,57 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Diagnosers; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [Config(typeof(MultipleJits))] + public class IntroDisassemblyAllJits + { + public class MultipleJits : ManualConfig + { + public MultipleJits() + { + AddJob(Job.ShortRun.WithPlatform(Platform.X86).WithRuntime(new MonoRuntime(name: "Mono x86", customPath: @"C:\Program Files (x86)\Mono\bin\mono.exe"))); + AddJob(Job.ShortRun.WithPlatform(Platform.X64).WithRuntime(new MonoRuntime(name: "Mono x64", customPath: @"C:\Program Files\Mono\bin\mono.exe"))); + + AddJob(Job.ShortRun.WithJit(Jit.LegacyJit).WithPlatform(Platform.X86).WithRuntime(ClrRuntime.Net462)); + AddJob(Job.ShortRun.WithJit(Jit.LegacyJit).WithPlatform(Platform.X64).WithRuntime(ClrRuntime.Net462)); + + AddJob(Job.ShortRun.WithJit(Jit.RyuJit).WithPlatform(Platform.X64).WithRuntime(ClrRuntime.Net462)); + + // RyuJit for .NET Core 5.0 + AddJob(Job.ShortRun.WithJit(Jit.RyuJit).WithPlatform(Platform.X64).WithRuntime(CoreRuntime.Core50)); + + AddDiagnoser(new DisassemblyDiagnoser(new DisassemblyDiagnoserConfig(maxDepth: 3, exportDiff: true))); + } + } + + private Increment increment = new Increment(); + + [Benchmark] + public int CallVirtualMethod() => increment.OperateTwice(10); + + public abstract class Operation // abstract unary integer operation + { + public abstract int Operate(int input); + + public int OperateTwice(int input) => Operate(Operate(input)); // two virtual calls to Operate + } + + public sealed class Increment : Operation // concrete, sealed operation: increment by fixed amount + { + public readonly int Amount; + public Increment(int amount = 1) { Amount = amount; } + + public override int Operate(int input) => input + Amount; + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroDisassemblyDry.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroDisassemblyDry.cs new file mode 100644 index 0000000..2a01eca --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroDisassemblyDry.cs @@ -0,0 +1,21 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [DisassemblyDiagnoser(maxDepth: 3)] + [DryJob] + public class IntroDisassemblyDry + { + [Benchmark] + public void Foo() + { + + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroDisassemblyRyuJit.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroDisassemblyRyuJit.cs new file mode 100644 index 0000000..97bd833 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroDisassemblyRyuJit.cs @@ -0,0 +1,39 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [DisassemblyDiagnoser(printSource: true)] + [RyuJitX64Job] + public class IntroDisassemblyRyuJit + { + private int[] field = Enumerable.Range(0, 100).ToArray(); + + [Benchmark] + public int SumLocal() + { + var local = field; // we use local variable that points to the field + + int sum = 0; + for (int i = 0; i < local.Length; i++) + sum += local[i]; + + return sum; + } + + [Benchmark] + public int SumField() + { + int sum = 0; + for (int i = 0; i < field.Length; i++) + sum += field[i]; + + return sum; + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroDotTraceDiagnoser.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroDotTraceDiagnoser.cs new file mode 100644 index 0000000..5b968e9 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroDotTraceDiagnoser.cs @@ -0,0 +1,32 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Diagnostics.dotTrace; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + // Enables dotTrace profiling for all jobs + [DotTraceDiagnoser] + // Adds the default "external-process" job + // Profiling is performed using dotTrace command-line Tools + // See: https://www.jetbrains.com/help/profiler/Performance_Profiling__Profiling_Using_the_Command_Line.html + [SimpleJob] + // Adds an "in-process" job + // Profiling is performed using dotTrace SelfApi + // NuGet reference: https://www.nuget.org/packages/JetBrains.Profiler.SelfApi + [InProcess] + public class IntroDotTraceDiagnoser + { + [Benchmark] + public void Fibonacci() => Fibonacci(30); + + private static int Fibonacci(int n) + { + return n <= 1 ? n : Fibonacci(n - 1) + Fibonacci(n - 2); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroEnvVars.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroEnvVars.cs new file mode 100644 index 0000000..69f4646 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroEnvVars.cs @@ -0,0 +1,36 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [Config(typeof(ConfigWithCustomEnvVars))] + public class IntroEnvVars + { + private class ConfigWithCustomEnvVars : ManualConfig + { + private const string JitNoInline = "COMPlus_JitNoInline"; + + public ConfigWithCustomEnvVars() + { + AddJob(Job.Default.WithRuntime(CoreRuntime.Core21).WithId("Inlining enabled")); + AddJob(Job.Default.WithRuntime(CoreRuntime.Core21) + .WithEnvironmentVariables(new EnvironmentVariable(JitNoInline, "1")) + .WithId("Inlining disabled")); + } + } + + [Benchmark] + public void Foo() + { + // Benchmark body + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroEventPipeProfiler.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroEventPipeProfiler.cs new file mode 100644 index 0000000..9a15c45 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroEventPipeProfiler.cs @@ -0,0 +1,20 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Diagnosers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [ShortRunJob] + [EventPipeProfiler(EventPipeProfile.CpuSampling)] + public class IntroEventPipeProfiler + { + [Benchmark] + public void Sleep() => Thread.Sleep(2000); + } + +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroEventPipeProfilerAdvanced.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroEventPipeProfilerAdvanced.cs new file mode 100644 index 0000000..2f3fabd --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroEventPipeProfilerAdvanced.cs @@ -0,0 +1,52 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Diagnosers; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using Microsoft.Diagnostics.NETCore.Client; +using Microsoft.Diagnostics.Tracing.Parsers; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Diagnostics.Tracing; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [Config(typeof(CustomConfig))] + public class IntroEventPipeProfilerAdvanced + { + private class CustomConfig : ManualConfig + { + public CustomConfig() + { + AddJob(Job.ShortRun.WithRuntime(CoreRuntime.Core50)); + + var providers = new[] + { + new EventPipeProvider(ClrTraceEventParser.ProviderName, EventLevel.Verbose, + (long) (ClrTraceEventParser.Keywords.Exception + | ClrTraceEventParser.Keywords.GC + | ClrTraceEventParser.Keywords.Jit + | ClrTraceEventParser.Keywords.JitTracing // for the inlining events + | ClrTraceEventParser.Keywords.Loader + | ClrTraceEventParser.Keywords.NGen)), + new EventPipeProvider("System.Buffers.ArrayPoolEventSource", EventLevel.Informational, long.MaxValue), + }; + + AddDiagnoser(new EventPipeProfiler(providers: providers)); + } + } + + [Benchmark] + public void RentAndReturn_Shared() + { + var pool = ArrayPool.Shared; + byte[] array = pool.Rent(10000); + pool.Return(array); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroExport.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroExport.cs new file mode 100644 index 0000000..3e8d397 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroExport.cs @@ -0,0 +1,43 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [ShortRunJob] + [MediumRunJob] + [KeepBenchmarkFiles] + + [AsciiDocExporter] + [CsvExporter] + [CsvMeasurementsExporter] + [HtmlExporter] + [PlainExporter] + [RPlotExporter] + [JsonExporterAttribute.Brief] + [JsonExporterAttribute.BriefCompressed] + [JsonExporterAttribute.Full] + [JsonExporterAttribute.FullCompressed] + [MarkdownExporterAttribute.Default] + [MarkdownExporterAttribute.GitHub] + [MarkdownExporterAttribute.StackOverflow] + [MarkdownExporterAttribute.Atlassian] + [XmlExporterAttribute.Brief] + [XmlExporterAttribute.BriefCompressed] + [XmlExporterAttribute.Full] + [XmlExporterAttribute.FullCompressed] + public class IntroExport + { + private Random random = new Random(42); + + [Benchmark(Baseline = true)] + public void Sleep10() => Thread.Sleep(10); + + [Benchmark] + public void Sleep50Noisy() => Thread.Sleep(random.Next(100)); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroExportJson.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroExportJson.cs new file mode 100644 index 0000000..6e45fad --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroExportJson.cs @@ -0,0 +1,48 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Exporters.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + // *** Attribute style *** + + [DryJob] + [JsonExporterAttribute.Brief] + [JsonExporterAttribute.Full] + [JsonExporterAttribute.BriefCompressed] + [JsonExporterAttribute.FullCompressed] + [JsonExporter("-custom", indentJson: true, excludeMeasurements: true)] + public class IntroExportJson + { + [Benchmark] public void Sleep10() => Thread.Sleep(10); + [Benchmark] public void Sleep20() => Thread.Sleep(20); + } + + // *** Object style *** + + [Config(typeof(Config))] + public class IntroJsonExportObjectStyle + { + private class Config : ManualConfig + { + public Config() + { + AddExporter(JsonExporter.Brief); + AddExporter(JsonExporter.Brief); + AddExporter(JsonExporter.Full); + AddExporter(JsonExporter.BriefCompressed); + AddExporter(JsonExporter.FullCompressed); + AddExporter(JsonExporter.Custom("-custom", indentJson: true, excludeMeasurements: true)); + } + } + + [Benchmark] public void Sleep10() => Thread.Sleep(10); + [Benchmark] public void Sleep20() => Thread.Sleep(20); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroExportXml.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroExportXml.cs new file mode 100644 index 0000000..1c069a3 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroExportXml.cs @@ -0,0 +1,22 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [DryJob] + [XmlExporterAttribute.Brief] + [XmlExporterAttribute.Full] + [XmlExporterAttribute.BriefCompressed] + [XmlExporterAttribute.FullCompressed] + [XmlExporter("-custom", indentXml: true, excludeMeasurements: true)] + public class IntroExportXml + { + [Benchmark] public void Sleep10() => Thread.Sleep(10); + [Benchmark] public void Sleep20() => Thread.Sleep(20); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroFilters.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroFilters.cs new file mode 100644 index 0000000..7edf1c4 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroFilters.cs @@ -0,0 +1,45 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Filters; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [DryJob] + [Config(typeof(Config))] + public class IntroFilters + { + private class Config : ManualConfig + { + // We will benchmark ONLY method with + // names (which contains "A" OR "1") AND (have length < 3) + public Config() + { + // benchmark with names which contains "A" OR "1" + AddFilter(new DisjunctionFilter( + new NameFilter(name => name.Contains("A")), + new NameFilter(name => name.Contains("1")) + )); + + // benchmark with names with length < 3 + AddFilter(new NameFilter(name => name.Length < 3)); + } + } + + [Benchmark] public void A1() => Thread.Sleep(10); // Will be benchmarked + [Benchmark] public void A2() => Thread.Sleep(10); // Will be benchmarked + [Benchmark] public void A3() => Thread.Sleep(10); // Will be benchmarked + [Benchmark] public void B1() => Thread.Sleep(10); // Will be benchmarked + [Benchmark] public void B2() => Thread.Sleep(10); + [Benchmark] public void B3() => Thread.Sleep(10); + [Benchmark] public void C1() => Thread.Sleep(10); // Will be benchmarked + [Benchmark] public void C2() => Thread.Sleep(10); + [Benchmark] public void C3() => Thread.Sleep(10); + [Benchmark] public void Aaa() => Thread.Sleep(10); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroFluentConfigBuilder.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroFluentConfigBuilder.cs new file mode 100644 index 0000000..f27e7f8 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroFluentConfigBuilder.cs @@ -0,0 +1,50 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Running; +using BenchmarkDotNet.Validators; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + public class Algo_Md5VsSha256 + { + private const int N = 10000; + private readonly byte[] data; + + private readonly MD5 md5 = MD5.Create(); + private readonly SHA256 sha256 = SHA256.Create(); + + public Algo_Md5VsSha256() + { + data = new byte[N]; + new Random(42).NextBytes(data); + } + + [Benchmark(Baseline = true)] + public byte[] Md5() => md5.ComputeHash(data); + + [Benchmark] + public byte[] Sha256() => sha256.ComputeHash(data); + } + + public class IntroFluentConfigBuilder + { + public static void Run() + { + BenchmarkRunner + .Run( + DefaultConfig.Instance + .AddJob(Job.Default.WithRuntime(ClrRuntime.Net462)) + .AddJob(Job.Default.WithRuntime(CoreRuntime.Core21)) + .AddValidator(ExecutionValidator.FailOnError)); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroGcMode.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroGcMode.cs new file mode 100644 index 0000000..e8093a1 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroGcMode.cs @@ -0,0 +1,49 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Order; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [Config(typeof(Config))] + [Orderer(SummaryOrderPolicy.FastestToSlowest)] + [MemoryDiagnoser] + public class IntroGcMode + { + private class Config : ManualConfig + { + public Config() + { + AddJob(Job.MediumRun.WithGcServer(true).WithGcForce(true).WithId("ServerForce")); + AddJob(Job.MediumRun.WithGcServer(true).WithGcForce(false).WithId("Server")); + AddJob(Job.MediumRun.WithGcServer(false).WithGcForce(true).WithId("Workstation")); + AddJob(Job.MediumRun.WithGcServer(false).WithGcForce(false).WithId("WorkstationForce")); + } + } + + [Benchmark(Description = "new byte[10kB]")] + public byte[] Allocate() + { + return new byte[10000]; + } + + [Benchmark(Description = "stackalloc byte[10kB]")] + public unsafe void AllocateWithStackalloc() + { + var array = stackalloc byte[10000]; + Consume(array); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static unsafe void Consume(byte* input) + { + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroGenericTypeArguments.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroGenericTypeArguments.cs new file mode 100644 index 0000000..33b5f96 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroGenericTypeArguments.cs @@ -0,0 +1,17 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [GenericTypeArguments(typeof(int))] + [GenericTypeArguments(typeof(char))] + public class IntroGenericTypeArguments + { + [Benchmark] public T Create() => Activator.CreateInstance(); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroHardwareCounters.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroHardwareCounters.cs new file mode 100644 index 0000000..8f55a70 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroHardwareCounters.cs @@ -0,0 +1,62 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Diagnosers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [HardwareCounters( + HardwareCounter.BranchMispredictions, + HardwareCounter.BranchInstructions)] + public class IntroHardwareCounters + { + private const int N = 32767; + private readonly int[] sorted, unsorted; + + public IntroHardwareCounters() + { + var random = new Random(0); + unsorted = new int[N]; + sorted = new int[N]; + for (int i = 0; i < N; i++) + sorted[i] = unsorted[i] = random.Next(256); + Array.Sort(sorted); + } + + private static int Branch(int[] data) + { + int sum = 0; + for (int i = 0; i < N; i++) + if (data[i] >= 128) + sum += data[i]; + return sum; + } + + private static int Branchless(int[] data) + { + int sum = 0; + for (int i = 0; i < N; i++) + { + int t = (data[i] - 128) >> 31; + sum += ~t & data[i]; + } + return sum; + } + + [Benchmark] + public int SortedBranch() => Branch(sorted); + + [Benchmark] + public int UnsortedBranch() => Branch(unsorted); + + [Benchmark] + public int SortedBranchless() => Branchless(sorted); + + [Benchmark] + public int UnsortedBranchless() => Branchless(unsorted); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroInProcess.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroInProcess.cs new file mode 100644 index 0000000..0dbc155 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroInProcess.cs @@ -0,0 +1,54 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Order; +using BenchmarkDotNet.Toolchains.InProcess.Emit; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [Config(typeof(Config))] + [Orderer(SummaryOrderPolicy.FastestToSlowest)] + [MemoryDiagnoser] + public class IntroInProcess + { + private class Config : ManualConfig + { + public Config() + { + AddJob(Job.MediumRun + .WithLaunchCount(1) + .WithId("OutOfProc")); + + AddJob(Job.MediumRun + .WithLaunchCount(1) + .WithToolchain(InProcessEmitToolchain.Instance) + .WithId("InProcess")); + } + } + + [Benchmark(Description = "new byte[10kB]")] + public byte[] Allocate() + { + return new byte[10000]; + } + + [Benchmark(Description = "stackalloc byte[10kB]")] + public unsafe void AllocateWithStackalloc() + { + var array = stackalloc byte[10000]; + Consume(array); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static unsafe void Consume(byte* input) + { + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroInProcessWrongEnv.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroInProcessWrongEnv.cs new file mode 100644 index 0000000..1d830e2 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroInProcessWrongEnv.cs @@ -0,0 +1,54 @@ +using System; +using System.Runtime.CompilerServices; +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Order; +using BenchmarkDotNet.Toolchains.InProcess; +using BenchmarkDotNet.Toolchains.InProcess.Emit; + +namespace TizenBenchmark.Intro +{ + [Config(typeof(Config))] + [Orderer(SummaryOrderPolicy.FastestToSlowest)] + [MemoryDiagnoser] + public class IntroInProcessWrongEnv + { + private class Config : ManualConfig + { + public Config() + { + var wrongPlatform = Environment.Is64BitProcess + ? Platform.X64 + : Platform.X86; + + AddJob(Job.MediumRun + .WithLaunchCount(1) + .WithPlatform(wrongPlatform) + .WithToolchain(InProcessEmitToolchain.Instance) + .WithId("InProcess")); + + AddValidator(InProcessValidator.DontFailOnError); + } + } + + [Benchmark(Description = "new byte[10kB]")] + public byte[] Allocate() + { + return new byte[10000]; + } + + [Benchmark(Description = "stackalloc byte[10kB]")] + public unsafe void AllocateWithStackalloc() + { + var array = stackalloc byte[10000]; + Consume(array); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static unsafe void Consume(byte* input) + { + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroInliningDiagnoser.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroInliningDiagnoser.cs new file mode 100644 index 0000000..3ea6e51 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroInliningDiagnoser.cs @@ -0,0 +1,42 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [BenchmarkDotNet.Diagnostics.Windows.Configs.InliningDiagnoser(logFailuresOnly: false, allowedNamespaces: new[] { "BenchmarkDotNet.Samples" })] + public class IntroInliningDiagnoser + { + [Benchmark] + public int IterationTest() + { + int j = 0; + for (int i = 0; i < short.MaxValue; ++i) + { + j = i + AddThree(i); + } + + return j + ReturnFive() + AddThree(ReturnFive()); + } + + [Benchmark] + public int SplitJoin() + => string.Join(",", new string[1000]).Split(',').Length; + + private int ReturnFive() + { + return 5; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private int AddThree(int a) + { + return a + 3; + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroJitStatsDiagnoser.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroJitStatsDiagnoser.cs new file mode 100644 index 0000000..9521be8 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroJitStatsDiagnoser.cs @@ -0,0 +1,14 @@ +using BenchmarkDotNet.Attributes; +using System.Threading; + +namespace TizenBenchmark.Intro +{ + + [BenchmarkDotNet.Diagnostics.Windows.Configs.JitStatsDiagnoser] + public class IntroJitStatsDiagnoser + { + [Benchmark] + public void Sleep() => Thread.Sleep(10); + } + +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroJobBaseline.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroJobBaseline.cs new file mode 100644 index 0000000..0672acc --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroJobBaseline.cs @@ -0,0 +1,21 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Jobs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [SimpleJob(runtimeMoniker: RuntimeMoniker.Net462, baseline: true)] + [SimpleJob(runtimeMoniker: RuntimeMoniker.Mono)] + [SimpleJob(runtimeMoniker: RuntimeMoniker.Net50)] + public class IntroJobBaseline + { + [Benchmark] + public int SplitJoin() + => string.Join(",", new string[1000]).Split(',').Length; + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroJoin.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroJoin.cs new file mode 100644 index 0000000..f9f874c --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroJoin.cs @@ -0,0 +1,36 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + // Run BenchmarkSwitcher with arguments: "--join --category=IntroJoinA" + + [DryJob] + public class IntroJoin1 + { + [Benchmark] + [BenchmarkCategory("IntroJoinA")] + public void A() => Thread.Sleep(10); + + [Benchmark] + [BenchmarkCategory("IntroJoinB")] + public void B() => Thread.Sleep(10); + } + + [DryJob] + public class IntroJoin2 + { + [Benchmark] + [BenchmarkCategory("IntroJoinA")] + public void A() => Thread.Sleep(10); + + [Benchmark] + [BenchmarkCategory("IntroJoinB")] + public void B() => Thread.Sleep(10); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroLargeAddressAware.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroLargeAddressAware.cs new file mode 100644 index 0000000..9fecc01 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroLargeAddressAware.cs @@ -0,0 +1,39 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using System; +using System.Runtime.InteropServices; + +namespace TizenBenchmark.Intro +{ + [MemoryDiagnoser] + [Config(typeof(Config))] + public class IntroLargeAddressAware + { + private class Config : ManualConfig + { + public Config() + { + AddJob(Job.Default + .WithRuntime(ClrRuntime.Net462) + .WithPlatform(Platform.X86) + .WithLargeAddressAware(value: RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + .WithId("Framework")); + } + } + + [Benchmark] + public void AllocateMoreThan2GB() + { + const int oneGB = 1024 * 1024 * 1024; + const int halfGB = oneGB / 2; + byte[] bytes1 = new byte[oneGB]; + byte[] bytes2 = new byte[oneGB]; + byte[] bytes3 = new byte[halfGB]; + GC.KeepAlive(bytes1); + GC.KeepAlive(bytes2); + GC.KeepAlive(bytes3); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroMonitoring.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroMonitoring.cs new file mode 100644 index 0000000..c51dd74 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroMonitoring.cs @@ -0,0 +1,24 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Engines; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [SimpleJob(RunStrategy.Monitoring, iterationCount: 10, id: "MonitoringJob")] + [MinColumn, Q1Column, Q3Column, MaxColumn] + public class IntroMonitoring + { + private Random random = new Random(42); + + [Benchmark] + public void Foo() + { + Thread.Sleep(random.Next(10) * 10); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroMultimodal.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroMultimodal.cs new file mode 100644 index 0000000..9bfaecc --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroMultimodal.cs @@ -0,0 +1,26 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Engines; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [MValueColumn] + [SimpleJob(RunStrategy.Throughput, 1, 0, -1, 1, "MyJob")] + public class IntroMultimodal + { + private readonly Random rnd = new Random(42); + + private void Multimodal(int n) + => Thread.Sleep((rnd.Next(n) + 1) * 100); + + [Benchmark] public void Unimodal() => Multimodal(1); + [Benchmark] public void Bimodal() => Multimodal(2); + [Benchmark] public void Trimodal() => Multimodal(3); + [Benchmark] public void Quadrimodal() => Multimodal(4); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroNativeMemory.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroNativeMemory.cs new file mode 100644 index 0000000..a005119 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroNativeMemory.cs @@ -0,0 +1,56 @@ +using System; +using System.Drawing; +using System.Runtime.InteropServices; +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Diagnostics.Windows.Configs; + +namespace TizenBenchmark.Intro +{ + [ShortRunJob] + [NativeMemoryProfiler] + [MemoryDiagnoser] + public class IntroNativeMemory + { + [Benchmark] + public void BitmapWithLeaks() + { + var flag = new Bitmap(200, 100); + var graphics = Graphics.FromImage(flag); + var blackPen = new Pen(Color.Black, 3); + graphics.DrawLine(blackPen, 100, 100, 500, 100); + } + + [Benchmark] + public void Bitmap() + { + using (var flag = new Bitmap(200, 100)) + { + using (var graphics = Graphics.FromImage(flag)) + { + using (var blackPen = new Pen(Color.Black, 3)) + { + graphics.DrawLine(blackPen, 100, 100, 500, 100); + } + } + } + } + + private const int Size = 20; // Greater value could cause System.OutOfMemoryException for test with memory leaks. + private int ArraySize = Size * Marshal.SizeOf(typeof(int)); + + [Benchmark] + public unsafe void AllocHGlobal() + { + IntPtr unmanagedHandle = Marshal.AllocHGlobal(ArraySize); + Span unmanaged = new Span(unmanagedHandle.ToPointer(), ArraySize); + Marshal.FreeHGlobal(unmanagedHandle); + } + + [Benchmark] + public unsafe void AllocHGlobalWithLeaks() + { + IntPtr unmanagedHandle = Marshal.AllocHGlobal(ArraySize); + Span unmanaged = new Span(unmanagedHandle.ToPointer(), ArraySize); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroNuGet.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroNuGet.cs new file mode 100644 index 0000000..c4a5fb2 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroNuGet.cs @@ -0,0 +1,47 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Jobs; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + /// + /// Benchmarks between various versions of a NuGet package + /// + /// + /// Only supported with the CsProjCoreToolchain toolchain + /// + [Config(typeof(Config))] + public class IntroNuGet + { + // Specify jobs with different versions of the same NuGet package to benchmark. + // The NuGet versions referenced on these jobs must be greater or equal to the + // same NuGet version referenced in this benchmark project. + // Example: This benchmark project references Newtonsoft.Json 9.0.1 + private class Config : ManualConfig + { + public Config() + { + var baseJob = Job.MediumRun; + + AddJob(baseJob.WithNuGet("Newtonsoft.Json", "11.0.2").WithId("11.0.2")); + AddJob(baseJob.WithNuGet("Newtonsoft.Json", "11.0.1").WithId("11.0.1")); + AddJob(baseJob.WithNuGet("Newtonsoft.Json", "10.0.3").WithId("10.0.3")); + AddJob(baseJob.WithNuGet("Newtonsoft.Json", "10.0.2").WithId("10.0.2")); + AddJob(baseJob.WithNuGet("Newtonsoft.Json", "10.0.1").WithId("10.0.1")); + AddJob(baseJob.WithNuGet("Newtonsoft.Json", "9.0.1").WithId("9.0.1")); + } + } + + [Benchmark] + public void SerializeAnonymousObject() + => JsonConvert.SerializeObject( + new { hello = "world", price = 1.99, now = DateTime.UtcNow }); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroOrderAttr.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroOrderAttr.cs new file mode 100644 index 0000000..d24e5c3 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroOrderAttr.cs @@ -0,0 +1,25 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Order; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [Orderer(SummaryOrderPolicy.FastestToSlowest, MethodOrderPolicy.Declared)] + [DryJob] + public class IntroOrderAttr + { + [Params(1, 2, 3)] + public int X { get; set; } + + [Benchmark] + public void Slow() => Thread.Sleep(X * 100); + + [Benchmark] + public void Fast() => Thread.Sleep(X * 50); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroOrderManual.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroOrderManual.cs new file mode 100644 index 0000000..610b9f9 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroOrderManual.cs @@ -0,0 +1,61 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Order; +using BenchmarkDotNet.Reports; +using BenchmarkDotNet.Running; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [Config(typeof(Config))] + [DryJob] + [RankColumn] + public class IntroOrderManual + { + private class Config : ManualConfig + { + public Config() => Orderer = new FastestToSlowestOrderer(); + + private class FastestToSlowestOrderer : IOrderer + { + public IEnumerable GetExecutionOrder(ImmutableArray benchmarksCase, + IEnumerable? order = null) => + from benchmark in benchmarksCase + orderby benchmark.Parameters["X"] descending, + benchmark.Descriptor.WorkloadMethodDisplayInfo + select benchmark; + + public IEnumerable GetSummaryOrder(ImmutableArray benchmarksCase, Summary summary) => + from benchmark in benchmarksCase + orderby summary[benchmark].ResultStatistics.Mean + select benchmark; + + public string GetHighlightGroupKey(BenchmarkCase benchmarkCase) => null; + + public string GetLogicalGroupKey(ImmutableArray allBenchmarksCases, BenchmarkCase benchmarkCase) => + benchmarkCase.Job.DisplayInfo + "_" + benchmarkCase.Parameters.DisplayInfo; + + public IEnumerable> GetLogicalGroupOrder(IEnumerable> logicalGroups, + IEnumerable? order = null) => + logicalGroups.OrderBy(it => it.Key); + + public bool SeparateLogicalGroups => true; + } + } + + [Params(1, 2, 3)] + public int X { get; set; } + + [Benchmark] + public void Fast() => Thread.Sleep(X * 50); + + [Benchmark] + public void Slow() => Thread.Sleep(X * 100); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroOutliers.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroOutliers.cs new file mode 100644 index 0000000..a12ebe2 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroOutliers.cs @@ -0,0 +1,37 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Jobs; +using Perfolizer.Mathematics.OutlierDetection; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [Config(typeof(Config))] + public class IntroOutliers + { + private class Config : ManualConfig + { + public Config() + { + var jobBase = Job.Default.WithWarmupCount(0).WithIterationCount(10).WithInvocationCount(1).WithUnrollFactor(1); + AddJob(jobBase.WithOutlierMode(OutlierMode.DontRemove).WithId("DontRemoveOutliers")); + AddJob(jobBase.WithOutlierMode(OutlierMode.RemoveUpper).WithId("RemoveUpperOutliers")); + } + } + + private int counter; + + [Benchmark] + public void Foo() + { + counter++; + int noise = counter % 10 == 0 ? 500 : 0; + Thread.Sleep(100 + noise); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroParams.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroParams.cs new file mode 100644 index 0000000..0e8b908 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroParams.cs @@ -0,0 +1,22 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + public class IntroParams + { + [Params(100, 200)] + public int A { get; set; } + + [Params(10, 20)] + public int B { get; set; } + + [Benchmark] + public void Benchmark() => Thread.Sleep(A + B + 5); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroParamsAllValues.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroParamsAllValues.cs new file mode 100644 index 0000000..947ce1b --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroParamsAllValues.cs @@ -0,0 +1,35 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [DryJob] + public class IntroParamsAllValues + { + public enum CustomEnum + { + One = 1, + Two, + Three + } + + [ParamsAllValues] + public CustomEnum E { get; set; } + + [ParamsAllValues] + public bool? B { get; set; } + + [Benchmark] + public void Benchmark() + { + Thread.Sleep( + (int)E * 100 + + (B == true ? 20 : B == false ? 10 : 0)); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroParamsSource.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroParamsSource.cs new file mode 100644 index 0000000..d06d4f3 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroParamsSource.cs @@ -0,0 +1,30 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + public class IntroParamsSource + { + // property with public setter + [ParamsSource(nameof(ValuesForA))] + public int A { get; set; } + + // public field + [ParamsSource(nameof(ValuesForB))] + public int B; + + // public property + public IEnumerable ValuesForA => new[] { 100, 200 }; + + // public static method + public static IEnumerable ValuesForB() => new[] { 10, 20 }; + + [Benchmark] + public void Benchmark() => Thread.Sleep(A + B + 5); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroPercentiles.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroPercentiles.cs new file mode 100644 index 0000000..9dfc833 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroPercentiles.cs @@ -0,0 +1,60 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Columns; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Engines; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + // Using percentiles for adequate timings representation + [Config(typeof(Config))] + [SimpleJob(RunStrategy.ColdStart, launchCount: 4, + warmupCount: 3, iterationCount: 20, id: "MyJob")] + public class IntroPercentiles + { + // To share between runs. + // DO NOT do this in production code. The System.Random IS NOT thread safe. + private static readonly Random Rnd = new Random(); + + private class Config : ManualConfig + { + public Config() + { + AddColumn( + StatisticColumn.P0, + StatisticColumn.P25, + StatisticColumn.P50, + StatisticColumn.P67, + StatisticColumn.P80, + StatisticColumn.P85, + StatisticColumn.P90, + StatisticColumn.P95, + StatisticColumn.P100); + } + } + + [Benchmark(Baseline = true)] + public void ConstantDelays() => Thread.Sleep(20); + + [Benchmark] + public void RandomDelays() => Thread.Sleep(10 + (int)(20 * Rnd.NextDouble())); + + [Benchmark] + public void RareDelays() + { + int rndTime = 10; + // Bigger delays for 15% of the runs + if (Rnd.NextDouble() > 0.85) + { + rndTime += 30; + } + + Thread.Sleep(rndTime); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroPowerPlan.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroPowerPlan.cs new file mode 100644 index 0000000..01e0524 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroPowerPlan.cs @@ -0,0 +1,46 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [Config(typeof(Config))] + public class IntroPowerPlan + { + private class Config : ManualConfig + { + public Config() + { + AddJob(Job.MediumRun.WithPowerPlan(new Guid("e9a42b02-d5df-448d-aa00-03f14749eb61"))); + AddJob(Job.MediumRun.WithPowerPlan(PowerPlan.UltimatePerformance)); + AddJob(Job.MediumRun.WithPowerPlan(PowerPlan.UserPowerPlan)); + AddJob(Job.MediumRun.WithPowerPlan(PowerPlan.HighPerformance)); + AddJob(Job.MediumRun.WithPowerPlan(PowerPlan.Balanced)); + AddJob(Job.MediumRun.WithPowerPlan(PowerPlan.PowerSaver)); + } + } + + [Benchmark] + public int IterationTest() + { + int j = 0; + for (int i = 0; i < short.MaxValue; ++i) + { + j = i; + } + + return j; + } + + [Benchmark] + public int SplitJoin() + => string.Join(",", new string[1000]).Split(',').Length; + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroRankColumn.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroRankColumn.cs new file mode 100644 index 0000000..3c1d3c8 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroRankColumn.cs @@ -0,0 +1,29 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Mathematics; +using BenchmarkDotNet.Order; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [ShortRunJob] + [Orderer(SummaryOrderPolicy.FastestToSlowest)] + [RankColumn(NumeralSystem.Arabic)] + [RankColumn(NumeralSystem.Roman)] + [RankColumn(NumeralSystem.Stars)] + public class IntroRankColumn + { + [Params(1, 2)] + public int Factor; + + [Benchmark] + public void Foo() => Thread.Sleep(Factor * 100); + + [Benchmark] + public void Bar() => Thread.Sleep(Factor * 200); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroRatioSD.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroRatioSD.cs new file mode 100644 index 0000000..e77dc4e --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroRatioSD.cs @@ -0,0 +1,38 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Engines; +using Perfolizer.Mathematics.OutlierDetection; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + // Don't remove outliers + [Outliers(OutlierMode.DontRemove)] + // Skip jitting, pilot, warmup; measure 10 iterations + [SimpleJob(RunStrategy.Monitoring, iterationCount: 10, invocationCount: 1)] + public class IntroRatioSD + { + private int counter; + + [GlobalSetup] + public void Setup() => counter = 0; + + [Benchmark(Baseline = true)] + public void Base() + { + Thread.Sleep(100); + if (++counter % 7 == 0) + Thread.Sleep(5000); // Emulate outlier + } + + [Benchmark] + public void Slow() => Thread.Sleep(200); + + [Benchmark] + public void Fast() => Thread.Sleep(50); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroRatioStyle.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroRatioStyle.cs new file mode 100644 index 0000000..09d85b9 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroRatioStyle.cs @@ -0,0 +1,34 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Columns; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Reports; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [ShortRunJob, Config(typeof(Config))] + public class IntroRatioStyle + { + [Benchmark(Baseline = true)] + public void Baseline() => Thread.Sleep(1000); + + [Benchmark] + public void Bar() => Thread.Sleep(150); + + [Benchmark] + public void Foo() => Thread.Sleep(1150); + + private class Config : ManualConfig + { + public Config() + { + SummaryStyle = SummaryStyle.Default.WithRatioStyle(RatioStyle.Trend); + } + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroSetupCleanupGlobal.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroSetupCleanupGlobal.cs new file mode 100644 index 0000000..801230d --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroSetupCleanupGlobal.cs @@ -0,0 +1,39 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + public class IntroSetupCleanupGlobal + { + [Params(10, 100, 1000)] + public int N; + + private int[] data; + + [GlobalSetup] + public void GlobalSetup() + { + data = new int[N]; // executed once per each N value + } + + [Benchmark] + public int Logic() + { + int res = 0; + for (int i = 0; i < N; i++) + res += data[i]; + return res; + } + + [GlobalCleanup] + public void GlobalCleanup() + { + // Disposing logic + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroSetupCleanupIteration.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroSetupCleanupIteration.cs new file mode 100644 index 0000000..92accd2 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroSetupCleanupIteration.cs @@ -0,0 +1,39 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Engines; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [SimpleJob(RunStrategy.Monitoring, launchCount: 1, + warmupCount: 2, iterationCount: 3)] + public class IntroSetupCleanupIteration + { + private int setupCounter; + private int cleanupCounter; + + [IterationSetup] + public void IterationSetup() + => Console.WriteLine($"// IterationSetup ({++setupCounter})"); + + [IterationCleanup] + public void IterationCleanup() + => Console.WriteLine($"// IterationCleanup ({++cleanupCounter})"); + + [GlobalSetup] + public void GlobalSetup() + => Console.WriteLine("// " + "GlobalSetup"); + + [GlobalCleanup] + public void GlobalCleanup() + => Console.WriteLine("// " + "GlobalCleanup"); + + [Benchmark] + public void Benchmark() + => Console.WriteLine("// " + "Benchmark"); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroSetupCleanupTarget.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroSetupCleanupTarget.cs new file mode 100644 index 0000000..fc8332f --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroSetupCleanupTarget.cs @@ -0,0 +1,40 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Engines; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [SimpleJob(RunStrategy.Monitoring, launchCount: 0, + warmupCount: 0, iterationCount: 1)] + public class IntroSetupCleanupTarget + { + [GlobalSetup(Target = nameof(BenchmarkA))] + public void GlobalSetupA() + => Console.WriteLine("// " + "GlobalSetup A"); + + [Benchmark] + public void BenchmarkA() + => Console.WriteLine("// " + "Benchmark A"); + + [GlobalSetup(Targets = new[] { nameof(BenchmarkB), nameof(BenchmarkC) })] + public void GlobalSetupB() + => Console.WriteLine("// " + "GlobalSetup B"); + + [Benchmark] + public void BenchmarkB() + => Console.WriteLine("// " + "Benchmark B"); + + [Benchmark] + public void BenchmarkC() + => Console.WriteLine("// " + "Benchmark C"); + + [Benchmark] + public void BenchmarkD() + => Console.WriteLine("// " + "Benchmark D"); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroStaThread.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroStaThread.cs new file mode 100644 index 0000000..a463eb7 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroStaThread.cs @@ -0,0 +1,23 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + public class IntroStaThread + { + [Benchmark, System.STAThread] + public void CheckForSTA() + { + if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) + { + throw new ThreadStateException( + "The current threads apartment state is not STA"); + } + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroStatisticalTesting.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroStatisticalTesting.cs new file mode 100644 index 0000000..c48b468 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroStatisticalTesting.cs @@ -0,0 +1,28 @@ +using BenchmarkDotNet.Attributes; +using Perfolizer.Mathematics.SignificanceTesting; +using Perfolizer.Mathematics.Thresholds; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [StatisticalTestColumn(StatisticalTestKind.Welch, ThresholdUnit.Microseconds, 1, true)] + [StatisticalTestColumn(StatisticalTestKind.MannWhitney, ThresholdUnit.Microseconds, 1, true)] + [StatisticalTestColumn(StatisticalTestKind.Welch, ThresholdUnit.Ratio, 0.03, true)] + [StatisticalTestColumn(StatisticalTestKind.MannWhitney, ThresholdUnit.Ratio, 0.03, true)] + [SimpleJob(warmupCount: 0, iterationCount: 5)] + public class IntroStatisticalTesting + { + [Benchmark] public void Sleep50() => Thread.Sleep(50); + [Benchmark] public void Sleep97() => Thread.Sleep(97); + [Benchmark] public void Sleep99() => Thread.Sleep(99); + [Benchmark(Baseline = true)] public void Sleep100() => Thread.Sleep(100); + [Benchmark] public void Sleep101() => Thread.Sleep(101); + [Benchmark] public void Sleep103() => Thread.Sleep(103); + [Benchmark] public void Sleep150() => Thread.Sleep(150); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroStatisticsColumns.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroStatisticsColumns.cs new file mode 100644 index 0000000..fbb7342 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroStatisticsColumns.cs @@ -0,0 +1,36 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [MediumRunJob, SkewnessColumn, KurtosisColumn] + public class IntroStatisticsColumns + { + private const int N = 10000; + private readonly byte[] data; + + private readonly MD5 md5 = MD5.Create(); + private readonly SHA256 sha256 = SHA256.Create(); + + public IntroStatisticsColumns() + { + data = new byte[N]; + new Random(42).NextBytes(data); + } + + [Benchmark(Baseline = true)] + public byte[] Md5A() => md5.ComputeHash(data); + + [Benchmark] + public byte[] Md5B() => md5.ComputeHash(data); + + [Benchmark] + public byte[] Sha256() => sha256.ComputeHash(data); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroStopOnFirstError.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroStopOnFirstError.cs new file mode 100644 index 0000000..d67db95 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroStopOnFirstError.cs @@ -0,0 +1,20 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [StopOnFirstError] + public class IntroStopOnFirstError + { + [Benchmark(Baseline = true)] + public int FirstMethod() => throw new Exception("Example exception."); + + [Benchmark] + public int SecondMethod() => 1; + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroTagColumn.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroTagColumn.cs new file mode 100644 index 0000000..5c3b362 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroTagColumn.cs @@ -0,0 +1,40 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Columns; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Jobs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + // You can add custom tags per each method using Columns + [Config(typeof(Config))] + public class IntroTagColumn + { + private class Config : ManualConfig + { + public Config() + { + AddJob(Job.Dry); + AddColumn(new TagColumn("Kind", name => name.Substring(0, 3))); + AddColumn(new TagColumn("Number", name => name.Substring(3))); + } + } + + [Benchmark] + public void Foo1() => Thread.Sleep(10); + + [Benchmark] + public void Foo12() => Thread.Sleep(10); + + [Benchmark] + public void Bar3() => Thread.Sleep(10); + + [Benchmark] + public void Bar34() => Thread.Sleep(10); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroTailcall.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroTailcall.cs new file mode 100644 index 0000000..999f0ba --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroTailcall.cs @@ -0,0 +1,28 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + [BenchmarkDotNet.Diagnostics.Windows.Configs.TailCallDiagnoser] + [LegacyJitX86Job, LegacyJitX64Job, RyuJitX64Job] + public class IntroTailcall + { + [Benchmark] + public long Calc() + => FactorialWithoutTailing(7) - FactorialWithTailing(7); + + private static long FactorialWithoutTailing(int depth) + => depth == 0 ? 1 : depth * FactorialWithoutTailing(depth - 1); + + private static long FactorialWithTailing(int pos, int depth) + => pos == 0 ? depth : FactorialWithTailing(pos - 1, depth * pos); + + private static long FactorialWithTailing(int depth) + => FactorialWithTailing(depth - 1, depth); + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroUnicode.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroUnicode.cs new file mode 100644 index 0000000..77dcd2d --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroUnicode.cs @@ -0,0 +1,69 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Running; +using BenchmarkDotNet.Toolchains.DotNetCli; +using BenchmarkDotNet.Toolchains.MonoWasm; +using BenchmarkDotNet.Toolchains; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using BenchmarkDotNet.Loggers; +using System.Diagnostics; + +namespace TizenBenchmark.Intro +{ + // *** Attribute Style *** + [UnicodeConsoleLogger] + public class IntroUnicode + { + [Benchmark] + public long Foo() + { + long waitUntil = Stopwatch.GetTimestamp() + 1000; + while (Stopwatch.GetTimestamp() < waitUntil) { } + return waitUntil; + } + } + + // *** Object Style *** + [Config(typeof(Config))] + public class IntroUnicodeObjectStyle + { + private class Config : ManualConfig + { + public Config() => AddLogger(ConsoleLogger.Unicode); + } + + [Benchmark] + public long Foo() + { + long waitUntil = Stopwatch.GetTimestamp() + 1000; + while (Stopwatch.GetTimestamp() < waitUntil) { } + return waitUntil; + } + } + + // *** Fluent Config *** + public class IntroUnicodeFluentConfig + { + public static void Run() + { + BenchmarkRunner.Run( + DefaultConfig.Instance + .AddLogger(ConsoleLogger.Unicode)); + } + + [Benchmark] + public long Foo() + { + long waitUntil = Stopwatch.GetTimestamp() + 1000; + while (Stopwatch.GetTimestamp() < waitUntil) { } + return waitUntil; + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/IntroWasm.cs b/tests/Benchmark/TizenBenchmark/Intro/IntroWasm.cs new file mode 100644 index 0000000..6872095 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/IntroWasm.cs @@ -0,0 +1,61 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Loggers; +using BenchmarkDotNet.Running; +using BenchmarkDotNet.Toolchains.DotNetCli; +using BenchmarkDotNet.Toolchains.MonoWasm; +using BenchmarkDotNet.Toolchains; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + // *** Command Line Arguments *** + public class IntroWasmCmdConfig + { + // the args must contain: + // an information that we want to run benchmark as Wasm: + // --runtimes Wasm + // path to dotnet cli + // --cli /home/adam/projects/runtime/dotnet.sh + public static void Run(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(IntroWasmCmdConfig).Assembly).Run(args); + + [Benchmark] + public void Foo() + { + // Benchmark body + } + } + + // *** Fluent Config *** + public class IntroWasmFluentConfig + { + public static void Run() + { + // the Wasm Toolchain requires two mandatory arguments: + const string cliPath = @"/home/adam/projects/runtime/dotnet.sh"; + + WasmRuntime runtime = new WasmRuntime(msBuildMoniker: "net5.0"); + NetCoreAppSettings netCoreAppSettings = new NetCoreAppSettings( + targetFrameworkMoniker: "net5.0", runtimeFrameworkVersion: null, name: "Wasm", + customDotNetCliPath: cliPath); + IToolchain toolChain = WasmToolchain.From(netCoreAppSettings); + + BenchmarkRunner.Run(DefaultConfig.Instance + .AddJob(Job.ShortRun.WithRuntime(runtime).WithToolchain(toolChain))); + } + + [Benchmark] + public void Foo() + { + // Benchmark body + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/Intro/TizenDotnet.cs b/tests/Benchmark/TizenBenchmark/Intro/TizenDotnet.cs new file mode 100644 index 0000000..d1109c5 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/Intro/TizenDotnet.cs @@ -0,0 +1,951 @@ +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Exporters; +using BenchmarkDotNet.Loggers; +using BenchmarkDotNet.Running; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TizenBenchmark.Intro +{ + public class TizenDotnet + { + void IntroArguments() + { + Console.WriteLine("##### IntroArguments Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroArguments Benchmark END #####"); + } + void IntroArgumentsSource() + { + Console.WriteLine("##### IntroArgumentsSource Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroArgumentsSource Benchmark END #####"); + } + void IntroArrayParam() + { + Console.WriteLine("##### IntroArrayParam Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroArrayParam Benchmark END #####"); + } + void IntroBasic() + { + Console.WriteLine("##### IntroBasic Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroBasic Benchmark END #####"); + } + void IntroBenchmarkBaseline() + { + Console.WriteLine("##### IntroBenchmarkBaseline Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroBenchmarkBaseline Benchmark END #####"); + } + void IntroCategories() + { + Console.WriteLine("##### IntroCategories Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroCategories Benchmark END #####"); + } + void IntroCategoryBaseline() + { + Console.WriteLine("##### IntroCategoryBaseline Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroCategoryBaseline Benchmark END #####"); + } + void IntroCategoryDiscoverer() + { + Console.WriteLine("##### IntroCategoryDiscoverer Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroCategoryDiscoverer Benchmark END #####"); + } + void IntroColdStart() + { + Console.WriteLine("##### IntroColdStart Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroColdStart Benchmark END #####"); + } + void IntroComparableComplexParam() + { + Console.WriteLine("##### IntroComparableComplexParam Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroComparableComplexParam Benchmark END #####"); + } + void IntroConfigSource() + { + Console.WriteLine("##### IntroConfigSource Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroConfigSource Benchmark END #####"); + } + void IntroConfigUnion() + { + Console.WriteLine("##### IntroConfigUnion Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroConfigUnion Benchmark END #####"); + } + void IntroCustomMono() + { + Console.WriteLine("##### IntroCustomMono Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + //var summary = BenchmarkRunner.Run(config); + //MarkdownExporter.Console.ExportToLog(summary, logger); + //Console.WriteLine(logger.GetLog()); + + //summary = BenchmarkRunner.Run(config); + //MarkdownExporter.Console.ExportToLog(summary, logger); + //Console.WriteLine(logger.GetLog()); + + //summary = BenchmarkRunner.Run(config); + //MarkdownExporter.Console.ExportToLog(summary, logger); + //Console.WriteLine(logger.GetLog()); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroCustomMono Benchmark END #####"); + } + void IntroCustomMonoArguments() + { + Console.WriteLine("##### IntroCustomMonoArguments Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroCustomMonoArguments Benchmark END #####"); + } + void IntroDeferredExecution() + { + Console.WriteLine("##### IntroDeferredExecution Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroDeferredExecution Benchmark END #####"); + } + void IntroDisassembly() + { + Console.WriteLine("##### IntroDisassembly Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroDisassembly Benchmark END #####"); + } + void IntroDisassemblyAllJits() + { + Console.WriteLine("##### IntroDisassemblyAllJits Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroDisassemblyAllJits Benchmark END #####"); + } + void IntroDisassemblyDry() + { + Console.WriteLine("##### IntroDisassemblyDry Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroDisassemblyDry Benchmark END #####"); + } + void IntroDisassemblyRyuJit() + { + Console.WriteLine("##### IntroDisassemblyRyuJit Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroDisassemblyRyuJit Benchmark END #####"); + } + void IntroDotTraceDiagnoser() + { + Console.WriteLine("##### IntroDotTraceDiagnoser Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroDotTraceDiagnoser Benchmark END #####"); + } + void IntroEnvVars() + { + Console.WriteLine("##### IntroEnvVars Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroEnvVars Benchmark END #####"); + } + void IntroEventPipeProfiler() + { + Console.WriteLine("##### IntroEventPipeProfiler Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroEventPipeProfiler Benchmark END #####"); + } + void IntroEventPipeProfilerAdvanced() + { + Console.WriteLine("##### IntroEventPipeProfilerAdvanced Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroEventPipeProfilerAdvanced Benchmark END #####"); + } + void IntroExport() + { + Console.WriteLine("##### IntroExport Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroExport Benchmark END #####"); + } + void IntroExportJson() + { + Console.WriteLine("##### IntroExportJson Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroExportJson Benchmark END #####"); + } + void IntroExportXml() + { + Console.WriteLine("##### IntroExportXml Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroExportXml Benchmark END #####"); + } + void IntroFilters() + { + Console.WriteLine("##### IntroFilters Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroFilters Benchmark END #####"); + } + void IntroFluentConfigBuilder() + { + Console.WriteLine("##### IntroFluentConfigBuilder Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroFluentConfigBuilder Benchmark END #####"); + } + void IntroGcMode() + { + Console.WriteLine("##### IntroGcMode Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroGcMode Benchmark END #####"); + } + void IntroGenericTypeArguments() + { + Console.WriteLine("##### IntroGenericTypeArguments Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run>(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + + summary = BenchmarkRunner.Run>(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroGenericTypeArguments Benchmark END #####"); + } + void IntroHardwareCounters() + { + Console.WriteLine("##### IntroHardwareCounters Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroHardwareCounters Benchmark END #####"); + } + void IntroInliningDiagnoser() + { + Console.WriteLine("##### IntroInliningDiagnoser Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroInliningDiagnoser Benchmark END #####"); + } + void IntroInProcess() + { + Console.WriteLine("##### IntroInProcess Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroInProcess Benchmark END #####"); + } + void IntroInProcessWrongEnv() + { + Console.WriteLine("##### IntroInProcessWrongEnv Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroInProcessWrongEnv Benchmark END #####"); + } + void IntroJitStatsDiagnoser() + { + Console.WriteLine("##### IntroJitStatsDiagnoser Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroJitStatsDiagnoser Benchmark END #####"); + } + void IntroJobBaseline() + { + Console.WriteLine("##### IntroJobBaseline Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroJobBaseline Benchmark END #####"); + } + void IntroJoin() + { + Console.WriteLine("##### IntroJoin Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + + summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroJoin Benchmark END #####"); + } + void IntroLargeAddressAware() + { + Console.WriteLine("##### IntroLargeAddressAware Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroLargeAddressAware Benchmark END #####"); + } + void IntroMonitoring() + { + Console.WriteLine("##### IntroMonitoring Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroMonitoring Benchmark END #####"); + } + void IntroMultimodal() + { + Console.WriteLine("##### IntroMultimodal Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroMultimodal Benchmark END #####"); + } + void IntroNativeMemory() + { + Console.WriteLine("##### IntroNativeMemory Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroNativeMemory Benchmark END #####"); + } + void IntroNuGet() + { + Console.WriteLine("##### IntroNuGet Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroNuGet Benchmark END #####"); + } + void IntroOrderAttr() + { + Console.WriteLine("##### IntroOrderAttr Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroOrderAttr Benchmark END #####"); + } + void IntroOrderManual() + { + Console.WriteLine("##### IntroOrderManual Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroOrderManual Benchmark END #####"); + } + void IntroOutliers() + { + Console.WriteLine("##### IntroOutliers Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroOutliers Benchmark END #####"); + } + void IntroParams() + { + Console.WriteLine("##### IntroParams Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroParams Benchmark END #####"); + } + void IntroParamsAllValues() + { + Console.WriteLine("##### IntroParamsAllValues Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroParamsAllValues Benchmark END #####"); + } + void IntroParamsSource() + { + Console.WriteLine("##### aIntroParamsSourceaa Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroParamsSource Benchmark END #####"); + } + void IntroPercentiles() + { + Console.WriteLine("##### IntroPercentiles Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroPercentiles Benchmark END #####"); + } + void IntroPowerPlan() + { + Console.WriteLine("##### IntroPowerPlan Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroPowerPlan Benchmark END #####"); + } + void IntroRankColumn() + { + Console.WriteLine("##### IntroRankColumn Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroRankColumn Benchmark END #####"); + } + void IntroRatioSD() + { + Console.WriteLine("##### IntroRatioSD Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroRatioSD Benchmark END #####"); + } + void IntroRatioStyle() + { + Console.WriteLine("##### IntroRatioStyle Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroRatioStyle Benchmark END #####"); + } + void IntroSetupCleanupGlobal() + { + Console.WriteLine("##### IntroSetupCleanupGlobal Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroSetupCleanupGlobal Benchmark END #####"); + } + void IntroSetupCleanupIteration() + { + Console.WriteLine("##### IntroSetupCleanupIteration Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroSetupCleanupIteration Benchmark END #####"); + } + void IntroSetupCleanupTarget() + { + Console.WriteLine("##### IntroSetupCleanupTarget Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroSetupCleanupTarget Benchmark END #####"); + } + void IntroStaThread() + { + Console.WriteLine("##### IntroStaThread Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroStaThread Benchmark END #####"); + } + void IntroStatisticalTesting() + { + Console.WriteLine("##### IntroStatisticalTesting Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroStatisticalTesting Benchmark END #####"); + } + void IntroStatisticsColumns() + { + Console.WriteLine("##### IntroStatisticsColumns Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroStatisticsColumns Benchmark END #####"); + } + void IntroStopOnFirstError() + { + Console.WriteLine("##### IntroStopOnFirstError Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroStopOnFirstError Benchmark END #####"); + } + void IntroTagColumn() + { + Console.WriteLine("##### IntroTagColumn Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroTagColumn Benchmark END #####"); + } + void IntroTailcall() + { + Console.WriteLine("##### IntroTailcall Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroTailcall Benchmark END #####"); + } + void IntroUnicode() + { + Console.WriteLine("##### IntroUnicode Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + + summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + + summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroUnicode Benchmark END #####"); + } + void IntroWasm() + { + Console.WriteLine("##### IntroWasm Benchmark START #####"); + var logger = new AccumulationLogger(); + var config = default(IConfig); + config = new DebugInProcessConfig(); + config = config.WithArtifactsPath("/tmp/BenchmarkDotnet"); + + var summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + + summary = BenchmarkRunner.Run(config); + MarkdownExporter.Console.ExportToLog(summary, logger); + Console.WriteLine(logger.GetLog()); + Console.WriteLine("##### IntroWasm Benchmark END #####"); + } + + + public void Benchmark() + { + Console.WriteLine("##### Tizen.NET Benchmark START #####"); + IntroArguments(); //1 + IntroArgumentsSource(); //1 + IntroArrayParam(); //1 + IntroBasic(); //1 + IntroBenchmarkBaseline(); //1 + //IntroCategories(); + IntroCategoryBaseline(); //1 + //IntroCategoryDiscoverer(); + //IntroColdStart(); + IntroComparableComplexParam(); //1 + //IntroConfigSource(); + //IntroConfigUnion(); + IntroCustomMono(); //1 + //IntroCustomMonoArguments(); + IntroDeferredExecution(); //1 + //IntroDisassembly(); + //IntroDisassemblyAllJits(); + //IntroDisassemblyDry(); + //IntroDisassemblyRyuJit(); + //IntroDotTraceDiagnoser(); + //IntroEnvVars(); + //IntroEventPipeProfiler(); + //IntroEventPipeProfilerAdvanced(); + //IntroExport(); + //IntroExportJson(); + //IntroExportXml(); + //IntroFilters(); + //IntroFluentConfigBuilder(); + //IntroGcMode(); + IntroGenericTypeArguments(); //2 + IntroHardwareCounters(); //1 + //IntroInliningDiagnoser(); + //IntroInProcess(); + IntroInProcessWrongEnv(); //1 + //IntroJitStatsDiagnoser(); + //IntroJobBaseline(); + //IntroJoin(); + //IntroLargeAddressAware(); + //IntroMonitoring(); + //IntroMultimodal(); + //IntroNativeMemory(); + //IntroNuGet(); + //IntroOrderAttr(); + //IntroOrderManual(); + //IntroOutliers(); + IntroParams(); //1 + //IntroParamsAllValues(); + IntroParamsSource(); //1 + //IntroPercentiles(); + //IntroPowerPlan(); + //IntroRankColumn(); + //IntroRatioSD(); + //IntroRatioStyle(); + IntroSetupCleanupGlobal(); //1 + //IntroSetupCleanupIteration(); + //IntroSetupCleanupTarget(); + IntroStaThread(); //1 + //IntroStatisticalTesting(); + //IntroStatisticsColumns(); + //IntroStopOnFirstError(); + //IntroTagColumn(); + //IntroTailcall(); + IntroUnicode(); //3 + IntroWasm(); //2 + Console.WriteLine("##### Tizen.NET Benchmark END #####"); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/TizenBenchmark.cs b/tests/Benchmark/TizenBenchmark/TizenBenchmark.cs new file mode 100644 index 0000000..d559200 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/TizenBenchmark.cs @@ -0,0 +1,51 @@ +using Tizen.NUI; +using Tizen.NUI.BaseComponents; + +namespace TizenBenchmark +{ + class Program : NUIApplication + { + protected override void OnCreate() + { + base.OnCreate(); + Initialize(); + } + + void Initialize() + { + Intro.TizenDotnet benchmark = new Intro.TizenDotnet(); + benchmark.Benchmark(); + + Window.Instance.KeyEvent += OnKeyEvent; + + TextLabel text = new TextLabel("Hello Tizen NUI World"); + text.HorizontalAlignment = HorizontalAlignment.Center; + text.VerticalAlignment = VerticalAlignment.Center; + text.TextColor = Color.Blue; + text.PointSize = 12.0f; + text.HeightResizePolicy = ResizePolicyType.FillToParent; + text.WidthResizePolicy = ResizePolicyType.FillToParent; + Window.Instance.GetDefaultLayer().Add(text); + + Animation animation = new Animation(2000); + animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X), 0, 500); + animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), 500, 1000); + animation.Looping = true; + animation.Play(); + } + + public void OnKeyEvent(object sender, Window.KeyEventArgs e) + { + if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape")) + { + Exit(); + } + } + + static void Main(string[] args) + { + var app = new Program(); + app.Run(args); + } + } +} diff --git a/tests/Benchmark/TizenBenchmark/TizenBenchmark.csproj b/tests/Benchmark/TizenBenchmark/TizenBenchmark.csproj new file mode 100644 index 0000000..0ce1585 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/TizenBenchmark.csproj @@ -0,0 +1,30 @@ + + + + Exe + net6.0-tizen + true + + + + portable + + + None + + + + + + + + + + + + + + + + + diff --git a/tests/Benchmark/TizenBenchmark/shared/res/TizenBenchmark.png b/tests/Benchmark/TizenBenchmark/shared/res/TizenBenchmark.png new file mode 100644 index 0000000..9f3cb98 Binary files /dev/null and b/tests/Benchmark/TizenBenchmark/shared/res/TizenBenchmark.png differ diff --git a/tests/Benchmark/TizenBenchmark/tizen-manifest.xml b/tests/Benchmark/TizenBenchmark/tizen-manifest.xml new file mode 100644 index 0000000..9ebeb6f --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/tizen-manifest.xml @@ -0,0 +1,16 @@ + + + + + + TizenBenchmark.png + + + diff --git a/tests/Benchmark/TizenBenchmark/tizen_dotnet_project.yaml b/tests/Benchmark/TizenBenchmark/tizen_dotnet_project.yaml new file mode 100644 index 0000000..2ad0cf0 --- /dev/null +++ b/tests/Benchmark/TizenBenchmark/tizen_dotnet_project.yaml @@ -0,0 +1,9 @@ +# csproj file path +csproj_file: TizenBenchmark.csproj + +# files monitored for dirty/modified status +files: + - TizenBenchmark.csproj + - TizenBenchmark.cs + - tizen-manifest.xml + - shared/res/TizenBenchmark.png \ No newline at end of file diff --git a/tests/Benchmark/org.tizen.dotnet.TizenBenchmark-1.0.0.tpk b/tests/Benchmark/org.tizen.dotnet.TizenBenchmark-1.0.0.tpk new file mode 100644 index 0000000..68102ad Binary files /dev/null and b/tests/Benchmark/org.tizen.dotnet.TizenBenchmark-1.0.0.tpk differ