Skip to content
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

Significantly improve .NET's code #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/
obj/
33 changes: 15 additions & 18 deletions dotnet/Program.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Threading.Tasks;

class Program
[assembly: SuppressMessage("Roslyn", "IDE0130", Justification = "This is a benchmark, we don't need to follow the usual naming conventions.")]
namespace AsyncRuntimeBenchmarks
{
static async Task Main(string[] args)
public sealed class Program
{
int numTasks = args.Length > 0 ? int.Parse(args[0]) : 100000;
Console.WriteLine($"Starting {numTasks} tasks");

List<Task> tasks = new List<Task>();

for (int i = 0; i < numTasks; i++)
public static async Task Main(string[] args)
{
Task task = Task.Run(async () =>
int numTasks = args.Length > 0 ? int.Parse(args[0], NumberStyles.Number, CultureInfo.InvariantCulture) : 100000;
Console.WriteLine($"Starting {numTasks} tasks");

Task[] tasks = new Task[numTasks];
for (int i = 0; i < numTasks; i++)
{
await Task.Delay(TimeSpan.FromSeconds(10));
});
tasks[i] = Task.Delay(TimeSpan.FromSeconds(10));
}
await Task.WhenAll(tasks);

tasks.Add(task);
Console.WriteLine("All tasks complete");
}

await Task.WhenAll(tasks);

Console.WriteLine("All tasks complete");
}
}
7 changes: 2 additions & 5 deletions dotnet/dotnet.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
</Project>