Skip to content

Instantly share code, notes, and snippets.

@ViktorHofer
Created February 16, 2018 02:59
Show Gist options
  • Save ViktorHofer/43a61de5cd7d3e45b29e36e7a40f21c2 to your computer and use it in GitHub Desktop.
Save ViktorHofer/43a61de5cd7d3e45b29e36e7a40f21c2 to your computer and use it in GitHub Desktop.
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains.CsProj;
using BenchmarkDotNet.Toolchains.DotNetCli;
using BenchmarkDotNet.Toolchains.InProcess;
using System;
using System.Linq;
namespace uribenchmark
{
public class UriBenchmark
{
private readonly char[] _chars = Enumerable.Range(33, 126).Select(i => (char)i).ToArray();
[Benchmark]
public void HexEscape()
{
for (int i = 0; i < 200_000; i++)
foreach (char c in _chars)
Uri.HexEscape(c);
}
}
class MainConfig : ManualConfig
{
public MainConfig()
{
// Job #1
// Add(Job.Default
// .With(Runtime.Core)
// .With(CsProjCoreToolchain.From(NetCoreAppSettings
// .NetCoreApp21
// .WithCustomDotNetCliPath(@"C:\dotnet\dotnet.exe", "OutOfProcessToolchain")))
// .WithId(".NET Core 2.1 master"));
// Job #2
Add(Job.Default
.With(InProcessToolchain.Instance)
.With(Runtime.Core)
.WithId(".NET Core 2.1 regex"));
Add(DefaultColumnProviders.Instance);
Add(MarkdownExporter.GitHub);
Add(new ConsoleLogger());
Add(new HtmlExporter());
Add(MemoryDiagnoser.Default);
}
}
class Program
{
static void Main(string[] args)
{
BenchmarkRunner.Run<UriBenchmark>(new MainConfig());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment