Hi, first time posting here, I'm really puzzle.
My company have legacy .NET application and we plan to move to .NET core.
While testing stuff I found the code slow. I did a minimal benchmark and it was 10x slower on my machine. The same identical code, same dev machine. I can repeat both code in any order and get always the same result.
Anyone have any clue why it would be that slower on .NET Core 3.1 vs .NET framework 4.7.2 ?
Both program were compiled with Visual Studio 2019 Community edition. I have been able to reproduce the issue with 2 machines (Windows 10 and Windows 7)
The code involve multi-thread download of files.
public static void Main(string[] args) {
object lockConsole = new object();
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
Parallel.For(0, 1000, new ParallelOptions { MaxDegreeOfParallelism = 20 },
i => {
try {
string url = $"https://www.merehelene.com/i/test-{i}.jpg?size=50";
Stopwatch sw = new Stopwatch();
sw.Start();
using (WebClient client = new WebClient()) {
client.DownloadData(url);
}
lock (lockConsole) {
Console.CursorLeft = 0;
Console.Write($"{sw.ElapsedMilliseconds}ms");
}
} catch (Exception e) {
Console.WriteLine(e.Message);
}
});
Console.WriteLine($"Total time: {stopwatch.ElapsedMilliseconds}ms");
Console.ReadLine();
}