Repository navigation
DEMO: Benchmark DTO, direct converter, and manual UOPD JSON - #155
Open
Brennan1994 wants to merge 2 commits into
Open
Brennan1994 wants to merge 2 commits into
Brennan1994 wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DEMO comparison of three JSON strategies for UncertainOrderedPairedData, based on InvestigateExistingJson (#152). All retain the IList API, existing distribution converter, list ownership, and collection validation. The DTO converter remains the default.
Direct and manual implementations explicitly handle required properties, unknown properties, non-finite numbers, and invalid inputs. The manual path uses case-sensitive default property names and numeric enums; it does not support custom serializer options. It rejects null Y distributions, computes ordinate validity when reading, and validates the completed collection once.
Benchmark results
BenchmarkDotNet 0.15.8, Release, .NET 10.0.9 x64 on Windows 11; one launch, five warmups, fifteen measurement iterations per case. Fixture: X=i, Y=Normal(10*i,1), strict ascending ordering, and default NaN tail probability. Setup verifies identical JSON and reconstructed data. Operations use JSON strings; deserialization includes validation. CPU model was not detected and BenchmarkDotNet could not change the power plan.
Each cell is mean elapsed microseconds / managed bytes allocated per call. Allocations are not peak live memory. All results come from the same 18-case run.
Manual deserialization uses 25-27% less time and allocates 13-19% fewer bytes than the DTO. At 1,000 ordinates, that saves about 218 microseconds and 56,616 allocated bytes per call. Across strategies, deserialization time and allocations scale approximately linearly.
Manual serialization provides small timing gains at larger sizes but allocates substantially more: at 1,000 ordinates, about 4% less time and 54% more allocated memory. Its Utf8JsonWriter-over-MemoryStream implementation uses writer and stream buffers in addition to the returned string. The serializer paths benefit from reusable writers and pooled buffers. Consequently, this comparison includes buffer-management differences as well as property-handling differences; it does not establish an inherent allocation penalty for manual JSON writing.
The direct converter does not consistently improve timing over the DTO. It saves 48 bytes per write but adds 328 bytes per read, where it allocates outer property-name strings. At 1,000 ordinates, DTO/direct timing confidence intervals overlap for both operations. Manual/DTO write intervals also overlap at 10 ordinates.
The full table, interpretation, methodology, and repeat command are saved at the top of UncertainPairedDataConverterBenchmarks.cs.
Validation
dotnet build -c Release: passed with zero warnings and errors.dotnet test -c Release --no-build --filter "TestCategory!=LiveServiceIntegration": 4,153 passed on net10.0 and 4,136 passed on net481; zero failures or skipped tests.