Skip to content

TaskAndValueTask: retarget net10.0, bump packages, add Task/ValueTask conversion test - #2128

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/78447-csharp-task-and-valuetask
Open

TaskAndValueTask: retarget net10.0, bump packages, add Task/ValueTask conversion test#2128
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/78447-csharp-task-and-valuetask

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Retargets the TaskAndValueTask sample to net10.0 and adds the missing conversion direction, for the republished article Task vs ValueTask in C#: When to Use Each.

  • All three projects move from net7.0 to net10.0.
  • BenchmarkDotNet 0.13.2 -> 0.15.8; Microsoft.NET.Test.Sdk 17.3.2 -> 18.9.0, xunit 2.4.2 -> 2.9.3, xunit.runner.visualstudio 2.4.5 -> 2.8.2, coverlet.collector 3.1.2 -> 10.0.1. This also clears the NU1903 advisory the old xunit runner pulled in through Newtonsoft.Json 9.0.1; the build is now warning-free.
  • New ConversionTests covering both directions between Task<T> and ValueTask<T> (new ValueTask<int>(Task<int>), new ValueTask<int>(int), .AsTask()). The article previously showed only AsTask().
  • Both benchmark methods now take the same city argument. TaskBenchmark ran on "Denver" and ValueTaskBenchmark on "London", so the two rows differed in their input as well as their return type.

Verified locally on SDK 10.0.302 / runtime 10.0.10: build 0 errors 0 warnings, dotnet test 6/6 passed, benchmark re-run (85.36 ns / 144 B for Task, 60.61 ns / 0 B for ValueTask).

… conversion test

Retarget all three projects from net7.0 to net10.0. Bump BenchmarkDotNet
0.13.2 -> 0.15.8 and the test packages (Microsoft.NET.Test.Sdk 17.3.2 ->
18.9.0, xunit 2.4.2 -> 2.9.3, xunit.runner.visualstudio 2.4.5 -> 2.8.2,
coverlet.collector 3.1.2 -> 10.0.1), which also clears the NU1903 advisory
the old xunit runner pulled in through Newtonsoft.Json 9.0.1.

Add ConversionTests, covering both directions between Task<T> and
ValueTask<T>: the ValueTask<T>(Task<T>) and ValueTask<T>(TResult)
constructors and AsTask().

Give both benchmark methods the same city argument. TaskBenchmark ran on
"Denver" and ValueTaskBenchmark on "London", so the two rows differed in
their input as well as their return type; with one city they differ only
in what is being measured.
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