代码语言:javascript复制
public void Queue()
{
var test = new ConcurrentQueue<TestModel>();//安全队列
//var test = Channel.CreateBounded(int.MaxValue);//管道
//var test = new Stack();//栈
//var test = new Queue();//队列
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(int.MaxValue);
//var test = new Stack();
//var test = new Queue();
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