public void Queue() { var test = new ConcurrentQueue<TestModel>();//安全队列 //var test = Channel.CreateBounded<TestModel>(int.MaxValue);//管道 //var test = new Stack<TestModel>();//栈 //var test = new Queue<TestModel>();//队列 for (int i = 0; i < 1_000_000; i++) { test.Enqueue(new TestModel()); //test.Writer.TryWrite(new TestModel()); //test.Push(new TestModel()); //test.Enqueue(new TestModel()); } } public void QueueIO() { var test = new ConcurrentQueue<TestModel>(); //var test = Channel.CreateBounded<TestModel>(int.MaxValue); //var test = new Stack<TestModel>(); //var test = new Queue<TestModel>(); for (int i = 0; i < 1_000_000; i++) { test.Enqueue(new TestModel()); //test.Writer.TryWrite(new TestModel()); //test.Push(new TestModel()); //test.Enqueue(new TestModel()); } for (int i = 0; i < 1_000_000; i++) { test.TryDequeue(out var _); //test.Reader.TryRead(out var _); //test.Pop(); //test.Dequeue(); } }
ConcurrentQueue和Queue的性能差别是纳米级大部分情况下都是使用ConcurrentQueue