using System; using System.Diagnostics; using System.Collections.Concurrent; public class Test { public static void Main() { while (true) { var q = new ConcurrentBag<int>() { 1, 2 }; var sw = new Stopwatch(); int gen0 = GC.CollectionCount(0), gen1 = GC.CollectionCount(1), gen2 = GC.CollectionCount(2); sw.Start(); for (int i = 0; i < 100_000_000; i++) { q.Add(i); q.TryTake(out int _); } sw.Stop(); Console.WriteLine($"Elapsed={sw.Elapsed} Gen0={GC.CollectionCount(0) - gen0} Gen1={GC.CollectionCount(1) - gen1} Gen2={GC.CollectionCount(2) - gen2}"); } } }