Ich würde erwarten, dass der Durchsatz für jede Aufgabe ziemlich konstant bleibt, bis Sie mehr Aufgaben als CPU-Kerne haben.
Auf meiner 28-Kern-CPU beginnt der Durchsatz pro Aufgabe jedoch abzufallen, nachdem nur 7 Aufgaben erstellt wurden, obwohl mein Task-Manager anzeigt, dass die CPU nicht einmal annähernd 100 % beträgt.
Ist diese Reduzierung pro Aufgabe durchweg rein aufgabenbedingt? Planung und Kontextwechsel oder mache ich etwas falsch?
Jede Hilfe wäre sehr dankbar
Code: Select all
class Program
{
static async Task Main()
{
var results = new Dictionary();
for (int workers = 1; workers
{
for (long j = 0; j < iterationsPerTask; j++)
{
_ = Math.Sqrt(j);
}
});
}
var sw = Stopwatch.StartNew();
await Task.WhenAll(tasks);
sw.Stop();
double perTaskThroughput = iterationsPerTask / sw.Elapsed.TotalSeconds;
results[workers] = perTaskThroughput;
}
foreach (var kvp in results)
{
Console.WriteLine($"{kvp.Key} Task(s): {kvp.Value:F2} iterations/sec per task");
}
}
}
Code: Select all
1 Task(s): 862577216.83 iterations/sec per task
2 Task(s): 858382140.23 iterations/sec per task
3 Task(s): 854105900.59 iterations/sec per task
4 Task(s): 840623005.88 iterations/sec per task
5 Task(s): 822938522.54 iterations/sec per task
6 Task(s): 847491885.90 iterations/sec per task
7 Task(s): 743713777.89 iterations/sec per task
8 Task(s): 794026695.97 iterations/sec per task
9 Task(s): 708545584.07 iterations/sec per task
10 Task(s): 690518224.95 iterations/sec per task
11 Task(s): 546421214.26 iterations/sec per task
12 Task(s): 583497432.26 iterations/sec per task
13 Task(s): 538722280.05 iterations/sec per task
14 Task(s): 563382376.52 iterations/sec per task
15 Task(s): 496078991.65 iterations/sec per task
16 Task(s): 478787579.62 iterations/sec per task
17 Task(s): 470389210.85 iterations/sec per task
18 Task(s): 463099341.43 iterations/sec per task
19 Task(s): 460345324.36 iterations/sec per task
20 Task(s): 419529729.83 iterations/sec per task
21 Task(s): 406272737.31 iterations/sec per task
22 Task(s): 380857188.42 iterations/sec per task
23 Task(s): 358325253.70 iterations/sec per task
24 Task(s): 362119687.87 iterations/sec per task
25 Task(s): 359521360.58 iterations/sec per task
26 Task(s): 338084788.22 iterations/sec per task
27 Task(s): 326119908.81 iterations/sec per task
28 Task(s): 311528692.48 iterations/sec per task
Mobile version