Skip to content

Use IReadOnlyList type-matching to avoid enumerator allocation. #279

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

AndreReise
Copy link
Contributor

Addresses #278

Benchmarks result

BenchmarkDotNet v0.14.0, Windows 10 (10.0.19045.5247/22H2/2022Update)
Intel Core i5-10300H CPU 2.50GHz, 1 CPU, 8 logical and 4 physical cores
.NET SDK 9.0.201
[Host] : .NET 8.0.15 (8.0.1525.16413), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.15 (8.0.1525.16413), X64 RyuJIT AVX2

Before

Method Mean Error StdDev Ratio RatioSD Gen0 Allocated Alloc Ratio
SerilogOnly 156.9 ns 1.23 ns 1.15 ns 1.00 0.01 0.0381 160 B 1.00
SimpleEvent 287.7 ns 2.51 ns 2.34 ns 1.83 0.02 0.0954 400 B 2.50
Template 359.9 ns 2.30 ns 2.04 ns 2.29 0.02 0.1144 480 B 3.00
StringScope 563.6 ns 4.04 ns 3.78 ns 3.59 0.03 0.2518 1056 B 6.60
TemplateScope 748.9 ns 12.41 ns 11.61 ns 4.77 0.08 0.3052 1280 B 8.00
TupleScope 512.4 ns 4.54 ns 4.02 ns 3.27 0.03 0.2232 936 B 5.85
DictionaryScope 531.2 ns 5.03 ns 4.46 ns 3.39 0.04 0.2670 1120 B 7.00
Capturing 703.1 ns 6.94 ns 5.80 ns 4.48 0.05 0.1850 776 B 4.85
CapturingScope 1,183.7 ns 17.00 ns 15.07 ns 7.55 0.11 0.4368 1832 B 11.45
LogInformationScoped 1,193.6 ns 14.11 ns 13.20 ns 7.61 0.10 0.4368 1832 B 11.45
LogInformation_WithEventId 794.8 ns 4.67 ns 4.14 ns 5.07 0.04 0.2441 1024 B 6.40

After

Method Mean Error StdDev Ratio RatioSD Gen0 Allocated Alloc Ratio
SerilogOnly 155.1 ns 1.33 ns 1.24 ns 1.00 0.01 0.0381 160 B 1.00
SimpleEvent 272.4 ns 1.34 ns 1.25 ns 1.76 0.02 0.0801 336 B 2.10
Template 328.5 ns 1.59 ns 1.49 ns 2.12 0.02 0.0992 416 B 2.60
StringScope 553.6 ns 5.53 ns 5.17 ns 3.57 0.04 0.2365 992 B 6.20
TemplateScope 714.0 ns 6.66 ns 5.91 ns 4.60 0.05 0.2899 1216 B 7.60
TupleScope 509.1 ns 9.61 ns 10.28 ns 3.28 0.07 0.2079 872 B 5.45
DictionaryScope 553.3 ns 5.68 ns 4.75 ns 3.57 0.04 0.2518 1056 B 6.60
Capturing 713.6 ns 7.60 ns 7.11 ns 4.60 0.06 0.1698 712 B 4.45
CapturingScope 1,163.2 ns 14.61 ns 12.20 ns 7.50 0.10 0.4215 1768 B 11.05
LogInformationScoped 1,163.0 ns 17.38 ns 13.57 ns 7.50 0.10 0.4215 1768 B 11.05
LogInformation_WithEventId 795.2 ns 15.27 ns 15.68 ns 5.13 0.11 0.2289 960 B 6.00

CC @nblumhardt

@nblumhardt
Copy link
Member

Thanks for this! I need a moment to take a closer look, will loop back as soon as I can 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants