Skip to content

Commit f6d5f63

Browse files
BenjaminAbtgfoidl
andauthored
add performance enhancements (#72)
Co-authored-by: Günther Foidl <[email protected]>
1 parent 879243b commit f6d5f63

File tree

16 files changed

+350
-25
lines changed

16 files changed

+350
-25
lines changed

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
// github copilot commit message instructions (preview)
3+
"github.copilot.chat.commitMessageGeneration.instructions": [
4+
{ "text": "Use conventional commit format: type(scope): description" },
5+
{ "text": "Use imperative mood: 'Add feature' not 'Added feature'" },
6+
{ "text": "Keep subject line under 50 characters" },
7+
{ "text": "Use types: feat, fix, docs, style, refactor, perf, test, chore, ci" },
8+
{ "text": "Include scope when relevant (e.g., api, ui, auth)" },
9+
{ "text": "Reference issue numbers with # prefix" }
10+
]
11+
}

.vscode/tasks.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "test",
6+
"type": "shell",
7+
"command": "dotnet test --nologo",
8+
"args": [],
9+
"problemMatcher": [
10+
"$msCompile"
11+
],
12+
"group": "build"
13+
}

Directory.Packages.props

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
</PropertyGroup>
55

6+
<ItemGroup Label="Default Dependencies">
7+
<PackageVersion Include="NaughtyStrings" Version="2.4.1" />
8+
</ItemGroup>
9+
610
<ItemGroup Label="Dependencies">
711
<PackageVersion Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
812
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
913
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
1014
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
11-
<PackageVersion Include="NaughtyStrings" Version="2.4.1" />
15+
1216
</ItemGroup>
1317

1418
<ItemGroup Label="Libraries for comparison">

Justfile

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Justfile .NET - Benjamin Abt 2025 - https://benjamin-abt.com
2+
# https://github.com/BenjaminAbt/templates/blob/main/justfile/dotnet
3+
4+
set shell := ["pwsh", "-c"]
5+
6+
# ===== Configurable defaults =====
7+
CONFIG := "Debug"
8+
TFM := "net10.0"
9+
BENCH_PRJ := "perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParser.Benchmarks.csproj"
10+
11+
# ===== Default / Help =====
12+
default: help
13+
14+
help:
15+
# Overview:
16+
just --list
17+
# Usage:
18+
# just build
19+
# just test
20+
# just bench
21+
22+
# ===== Basic .NET Workflows =====
23+
restore:
24+
dotnet restore
25+
26+
build *ARGS:
27+
dotnet build --configuration "{{CONFIG}}" --nologo --verbosity minimal {{ARGS}}
28+
29+
rebuild *ARGS:
30+
dotnet build --configuration "{{CONFIG}}" --nologo --verbosity minimal --no-incremental {{ARGS}}
31+
32+
clean:
33+
dotnet clean --configuration "{{CONFIG}}" --nologo
34+
35+
run *ARGS:
36+
dotnet run --project --framework "{{TFM}}" --configuration "{{CONFIG}}" --no-launch-profile {{ARGS}}
37+
38+
# ===== Quality / Tests =====
39+
format:
40+
dotnet format --verbosity minimal
41+
42+
format-check:
43+
dotnet format --verify-no-changes --verbosity minimal
44+
45+
test *ARGS:
46+
dotnet test --configuration "{{CONFIG}}" --framework "{{TFM}}" --nologo --verbosity minimal {{ARGS}}
47+
48+
test-cov:
49+
dotnet test --configuration "{{CONFIG}}" --framework "{{TFM}}" --nologo --verbosity minimal /p:CollectCoverage=true /p:CoverletOutputFormat="cobertura,lcov,opencover" /p:CoverletOutput="./TestResults/coverage/coverage"
50+
51+
52+
test-filter QUERY:
53+
dotnet test --configuration "{{CONFIG}}" --framework "{{TFM}}" --nologo --verbosity minimal --filter "{{QUERY}}"
54+
55+
# ===== Packaging / Release =====
56+
pack *ARGS:
57+
dotnet pack --configuration "{{CONFIG}}" --nologo --verbosity minimal -o "./artifacts/packages" {{ARGS}}
58+
59+
publish *ARGS:
60+
dotnet publish --configuration "{{CONFIG}}" --framework "{{TFM}}" --nologo --verbosity minimal -o "./artifacts/publish/{{TFM}}" {{ARGS}}
61+
62+
publish-sc RID *ARGS:
63+
dotnet publish --configuration "{{CONFIG}}" --framework "{{TFM}}" --runtime "{{RID}}" --self-contained true -p:PublishSingleFile=true -p:PublishTrimmed=false --nologo --verbosity minimal -o "./artifacts/publish/{{TFM}}-{{RID}}" {{ARGS}}
64+
65+
# ===== Benchmarks =====
66+
bench *ARGS:
67+
dotnet run --configuration Release --project "{{BENCH_PRJ}}" --framework "{{TFM}}" {{ARGS}}
68+
69+
# ===== Housekeeping =====
70+
clean-artifacts:
71+
if (Test-Path "./artifacts") { Remove-Item "./artifacts" -Recurse -Force }
72+
73+
clean-all:
74+
just clean
75+
just clean-artifacts
76+
# Optionally: git clean -xdf
77+
78+
# ===== Combined Flows =====
79+
fmt-build:
80+
just format
81+
just build
82+
83+
ci:
84+
just clean
85+
just restore
86+
just format-check
87+
just build
88+
just test-cov

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021-2023 MyCSharp
3+
Copyright (c) 2021-2025 MyCSharp
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

MyCSharp.HttpUserAgentParser.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_", "_", "{5738CE0D-5E6E-47
2727
Directory.Build.props = Directory.Build.props
2828
Directory.Packages.props = Directory.Packages.props
2929
global.json = global.json
30+
Justfile = Justfile
3031
LICENSE = LICENSE
3132
NuGet.config = NuGet.config
3233
README.md = README.md
@@ -81,6 +82,16 @@ Global
8182
GlobalSection(SolutionProperties) = preSolution
8283
HideSolutionNode = FALSE
8384
EndGlobalSection
85+
GlobalSection(NestedProjects) = preSolution
86+
{45927CF7-1BF4-479B-BBAA-8AD9CA901AE4} = {008A2BAB-78B4-42EB-A5D4-DE434438CEF0}
87+
{3357BEC0-8216-409E-A539-F9A71DBACB81} = {008A2BAB-78B4-42EB-A5D4-DE434438CEF0}
88+
{F16697F7-74B4-441D-A0C0-1A0572AC3AB0} = {F54C9296-4EF7-40F0-9F20-F23A2270ABC9}
89+
{75960783-8BF9-479C-9ECF-E9653B74C9A2} = {F54C9296-4EF7-40F0-9F20-F23A2270ABC9}
90+
{3C8CCD44-F47C-4624-8997-54C42F02E376} = {008A2BAB-78B4-42EB-A5D4-DE434438CEF0}
91+
{39FC1EC2-2AD3-411F-A545-AB6CCB94FB7E} = {F54C9296-4EF7-40F0-9F20-F23A2270ABC9}
92+
{A0D213E9-6408-46D1-AFAF-5096C2F6E027} = {FAAD18A0-E1B8-448D-B611-AFBDA8A89808}
93+
{165EE915-1A4F-4875-90CE-1A2AE1540AE7} = {F54C9296-4EF7-40F0-9F20-F23A2270ABC9}
94+
EndGlobalSection
8495
GlobalSection(ExtensibilityGlobals) = postSolution
8596
SolutionGuid = {E8B0C994-0BF2-4692-9E22-E48B265B2804}
8697
EndGlobalSection

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ by [@BenjaminAbt](https://github.com/BenjaminAbt) and [@gfoidl](https://github.c
141141

142142
MIT License
143143

144-
Copyright (c) 2021-2023 MyCSharp
144+
Copyright (c) 2021-2025 MyCSharp
145145

146146
Permission is hereby granted, free of charge, to any person obtaining a copy
147147
of this software and associated documentation files (the "Software"), to deal

perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParser.Benchmarks.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
<Nullable>disable</Nullable>
66
</PropertyGroup>
77

8+
<!-- Use project build name as assembly name to satisfy benchmark.NET -->
9+
<PropertyGroup>
10+
<RootNamespace>$(MSBuildProjectName)</RootNamespace>
11+
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
12+
</PropertyGroup>
13+
814
<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
915
<DefineConstants>$(DefineConstants);OS_WIN</DefineConstants>
1016
</PropertyGroup>

perf/HttpUserAgentParser.Benchmarks/HttpUserAgentParserBenchmarks.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
using BenchmarkDotNet.Attributes;
44
using BenchmarkDotNet.Jobs;
5+
using MyCSharp.HttpUserAgentParser;
56

67
#if OS_WIN
78
using BenchmarkDotNet.Diagnostics.Windows.Configs;
89
#endif
910

10-
namespace MyCSharp.HttpUserAgentParser.Benchmarks;
11+
namespace HttpUserAgentParser.Benchmarks;
1112

1213
[MemoryDiagnoser]
1314
[SimpleJob(RuntimeMoniker.Net80)]
@@ -43,7 +44,7 @@ public void Parse()
4344

4445
for (int i = 0; i < testUserAgentMix.Length; ++i)
4546
{
46-
results[i] = HttpUserAgentParser.Parse(testUserAgentMix[i]);
47+
results[i] = MyCSharp.HttpUserAgentParser.HttpUserAgentParser.Parse(testUserAgentMix[i]);
4748
}
4849
}
4950
}

perf/HttpUserAgentParser.Benchmarks/LibraryComparison/LibraryComparisonBenchmarks.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
using BenchmarkDotNet.Configs;
66
using BenchmarkDotNet.Diagnosers;
77
using DeviceDetectorNET;
8+
using MyCSharp.HttpUserAgentParser;
89
using MyCSharp.HttpUserAgentParser.Providers;
910

10-
namespace MyCSharp.HttpUserAgentParser.Benchmarks.LibraryComparison;
11+
namespace HttpUserAgentParser.Benchmarks.LibraryComparison;
1112

1213
[ShortRunJob]
1314
[MemoryDiagnoser]
@@ -33,7 +34,7 @@ public IEnumerable<TestData> GetTestUserAgents()
3334
[BenchmarkCategory("Basic")]
3435
public HttpUserAgentInformation MyCSharpBasic()
3536
{
36-
HttpUserAgentInformation info = HttpUserAgentParser.Parse(Data.UserAgent);
37+
HttpUserAgentInformation info = MyCSharp.HttpUserAgentParser.HttpUserAgentParser.Parse(Data.UserAgent);
3738
return info;
3839
}
3940

0 commit comments

Comments
 (0)