DTLib.Demystifier/test/Ben.Demystifier.Benchmarks/Exceptions.cs
Sergey Teplyakov 125e373b45 Remove the dependency on System.ValueTuple (#63)
* Add an option to get tuple data via reflection.

* Removed non-relfection-based way of getting information about the tuples.

* Make methods static back.

* Remove the nuget dependency to System.ValueTuple
2018-02-23 11:24:41 +00:00

41 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Jobs;
namespace Ben.Demystifier.Benchmarks
{
[ClrJob, CoreJob]
[Config(typeof(Config))]
public class ExceptionTests
{
[Benchmark(Baseline = true, Description = ".ToString()")]
public string Baseline() => new Exception().ToString();
[Benchmark(Description = "Demystify().ToString()")]
public string Demystify() => new Exception().Demystify().ToString();
[Benchmark(Description = "(left, right).ToString()")]
public string ToStringForTupleBased() => GetException(() => ReturnsTuple()).ToString();
[Benchmark(Description = "(left, right).Demystify().ToString()")]
public string ToDemystifyForTupleBased() => GetException(() => ReturnsTuple()).Demystify().ToString();
private static Exception GetException(Action action)
{
try
{
action();
throw new InvalidOperationException("Should not be reachable.");
}
catch (Exception e)
{
return e;
}
}
private static List<(int left, int right)> ReturnsTuple() => throw new Exception();
}
}