Skip to content

Benchmarks #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
branches:
- main
pull_request:
types: [closed]
branches:
- main

Expand Down
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<DebugType>embedded</DebugType>
<IsPackable>false</IsPackable>
</PropertyGroup>
</Project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright © myCSharp 2020-2021, all rights reserved

using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;

#if OS_WIN
using BenchmarkDotNet.Diagnostics.Windows.Configs;
#endif

namespace MyCSharp.HttpUserAgentParser.Benchmarks
{
[MemoryDiagnoser]
#if OS_WIN
[EtwProfiler] // needs admin-rights
#endif
public class HttpUserAgentParserBenchmarks
{
private string[] _testUserAgentMix;
private HttpUserAgentInformation[] _results;

[GlobalSetup]
public void GlobalSetup()
{
_testUserAgentMix = GetTestUserAgents().ToArray();
_results = new HttpUserAgentInformation[_testUserAgentMix.Length];
}

private static IEnumerable<string> GetTestUserAgents()
{
yield return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36";
yield return "APIs-Google (+https://developers.google.com/webmasters/APIs-Google.html)";
yield return "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0";
yield return "yeah I'm unknown user agent, just to bring some fun to the mix";
}

[Benchmark]
public void Parse()
{
string[] testUserAgentMix = _testUserAgentMix;
HttpUserAgentInformation[] results = _results;

for (int i = 0; i < testUserAgentMix.Length; ++i)
{
results[i] = HttpUserAgentParser.Parse(testUserAgentMix[i]);
}
}
}
}
Loading