{"id":20605146,"url":"https://github.com/arnab-developer/task-vs-valuetask","last_synced_at":"2026-04-20T11:05:10.778Z","repository":{"id":68915408,"uuid":"466672790","full_name":"Arnab-Developer/task-vs-valuetask","owner":"Arnab-Developer","description":"Comparison between 'Task' and 'ValueTask'","archived":false,"fork":false,"pushed_at":"2022-05-13T04:00:40.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-17T02:24:11.264Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Arnab-Developer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-06T07:57:24.000Z","updated_at":"2022-03-06T08:31:34.000Z","dependencies_parsed_at":"2023-04-09T14:49:09.375Z","dependency_job_id":null,"html_url":"https://github.com/Arnab-Developer/task-vs-valuetask","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arnab-Developer%2Ftask-vs-valuetask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arnab-Developer%2Ftask-vs-valuetask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arnab-Developer%2Ftask-vs-valuetask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arnab-Developer%2Ftask-vs-valuetask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Arnab-Developer","download_url":"https://codeload.github.com/Arnab-Developer/task-vs-valuetask/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242250932,"owners_count":20096895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T09:26:48.125Z","updated_at":"2026-04-20T11:05:10.711Z","avatar_url":"https://github.com/Arnab-Developer.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Task vs ValueTask\n\nComparison between `Task` and `ValueTask` in C#.\n\nIf your code's execution path is synchronous in most of the cases and sometimes asynchronous then you can use `ValueTask` to reduce some memory allocation. But if your code's execution path is always asynchronous then `Task` should be used. Because in that case we will not get any performance benefit by using `ValueTask` over `Task`.\n\n## Benchmark comparison result\n\nBenchmark comparison result of the code which is always asynchronous.\n\n```\n// * Summary *\n\nBenchmarkDotNet=v0.13.1, OS=Windows 10.0.22000\nIntel Xeon Platinum 8272CL CPU 2.60GHz, 1 CPU, 2 logical and 2 physical cores\n.NET SDK=6.0.200\n  [Host]     : .NET 6.0.2 (6.0.222.6406), X64 RyuJIT\n  DefaultJob : .NET 6.0.2 (6.0.222.6406), X64 RyuJIT\n\n|            Method |    Mean |    Error |   StdDev |  Median | Allocated |\n|------------------ |--------:|---------:|---------:|--------:|----------:|\n|      ReadWithTask | 1.171 s | 0.0325 s | 0.0884 s | 1.215 s |    205 KB |\n| ReadWithValueTask | 1.191 s | 0.0248 s | 0.0654 s | 1.219 s |    205 KB |\n```\n\nBenchmark comparison result of the code which is 99% of the times synchronous and 1% of time asynchronous.\n\n```\n// * Summary *\n\nBenchmarkDotNet=v0.13.1, OS=Windows 10.0.22000\nIntel Xeon Platinum 8272CL CPU 2.60GHz, 1 CPU, 2 logical and 2 physical cores\n.NET SDK=6.0.200\n  [Host]     : .NET 6.0.2 (6.0.222.6406), X64 RyuJIT\n  DefaultJob : .NET 6.0.2 (6.0.222.6406), X64 RyuJIT\n\n|            Method |    Mean |    Error |   StdDev |       Gen 0 | Allocated |\n|------------------ |--------:|---------:|---------:|------------:|----------:|\n|      ReadWithTask | 4.123 s | 0.0511 s | 0.0478 s | 513000.0000 |      9 GB |\n| ReadWithValueTask | 3.738 s | 0.0167 s | 0.0157 s | 128000.0000 |      2 GB |\n```\n\n## References\n\n- https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.valuetask\n- https://www.youtube.com/watch?v=IN4dRdKlISI\n- https://www.youtube.com/watch?v=mEhkelf0K6g\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnab-developer%2Ftask-vs-valuetask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farnab-developer%2Ftask-vs-valuetask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnab-developer%2Ftask-vs-valuetask/lists"}