Skip to content

DifferencesBetweenSpanAndMemoryInCSharp: retarget net10.0, return the slice from both benchmarks - #2129

Merged
vladimir-pecanac-main merged 3 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/117035-csharp-differences-between-span-and-memory
Aug 27, 2026
Merged

DifferencesBetweenSpanAndMemoryInCSharp: retarget net10.0, return the slice from both benchmarks#2129
vladimir-pecanac-main merged 3 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/117035-csharp-differences-between-span-and-memory

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Both benchmark methods in SpanMemoryBenchmark returned void and discarded their slice, so the published means (0.2760 ns / 0.0239 ns) measured an empty method rather than the operation. Returning the slice makes BenchmarkDotNet consume the result.

  • SliceAsMemory now returns Memory<int>, SliceAsSpan now returns Span<int>
  • Retargeted net8.0 -> net10.0

Measured on net10.0 (.NET 10.0.10, BenchmarkDotNet 0.13.12): SliceAsMemory 2.8710 ns, SliceAsSpan 0.5306 ns, 0 B allocated. Article /csharp-differences-between-span-and-memory/ updated with these figures.

… slice from both benchmarks

Both benchmark methods returned void and discarded their slice, so the
published means (0.2760 ns / 0.0239 ns) measured an empty method rather
than the operation. Returning the slice makes BenchmarkDotNet consume the
result and produces real figures.
@vladimir-pecanac-main
vladimir-pecanac-main merged commit c287ec3 into CodeMazeBlog:main Aug 27, 2026
3 checks passed
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.

1 participant