Performance Test of list <t>, queue list <t>, queue <t>, concurrentqueue <t>

Source: Internet
Author: User
            //Test Group 1            {                var watch = Stopwatch.StartNew();                var list = new List<int>();                for (int j = 0; j < 300000; j++)                {                    list.Insert(0, j);                }                watch.Stop();                Console.WriteLine("Insert First::List::" + watch.ElapsedMilliseconds);            }            {                var watch = Stopwatch.StartNew();                var list = new LinkedList<int>();                for (int j = 0; j < 300000; j++)                {                    list.AddFirst(j);                }                watch.Stop();                Console.WriteLine("Insert First::LinkedList::" + watch.ElapsedMilliseconds);            }            //Test Group 2:            {                var watch = Stopwatch.StartNew();                var list = new List<int>();                for (int j = 0; j < 300000; j++)                {                    list.Add(j);                }                watch.Stop();                Console.WriteLine("Append::List::" + watch.ElapsedMilliseconds);            }            {                var watch = Stopwatch.StartNew();                var list = new LinkedList<int>();                for (int j = 0; j < 300000; j++)                {                    list.AddLast(j);                }                watch.Stop();                Console.WriteLine("Append::LinkedList::" + watch.ElapsedMilliseconds);            }            {                var watch = Stopwatch.StartNew();                var queue = new Queue<int>();                for (int j = 0; j < 300000; j++)                {                    queue.Enqueue(j);                }                watch.Stop();                Console.WriteLine("Enqueue::Queue::" + watch.ElapsedMilliseconds);            }            {                var watch = Stopwatch.StartNew();                var queue = new ConcurrentQueue<int>();                for (int j = 0; j < 300000; j++)                {                    queue.Enqueue(j);                }                watch.Stop();                Console.WriteLine("Enqueue::ConcurrentQueue::" + watch.ElapsedMilliseconds);            }            //Test Group 3:            {                var list = new List<int>();                for (int j = 0; j < 300000; j++)                {                    list.Add(j);                }                var watch = Stopwatch.StartNew();                for (int j = 0; j < 300000; j++)                {                    var value = list[0];                    list.RemoveAt(0);                }                watch.Stop();                Console.WriteLine("RemoveAt(0)::List::" + watch.ElapsedMilliseconds);            }            {                var list = new LinkedList<int>();                for (int j = 0; j < 300000; j++)                {                    list.AddLast(j);                }                var watch = Stopwatch.StartNew();                for (int j = 0; j < 300000; j++)                {                    var value = list.First.Value;                    list.RemoveFirst();                }                watch.Stop();                Console.WriteLine("RemoveFirst::LinkedList::" + watch.ElapsedMilliseconds);            }            {                var queue = new Queue<int>();                for (int j = 0; j < 300000; j++)                {                    queue.Enqueue(j);                }                var watch = Stopwatch.StartNew();                for (int j = 0; j < 300000; j++)                {                    var value = queue.Dequeue();                }                watch.Stop();                Console.WriteLine("Dequeue::Queue::" + watch.ElapsedMilliseconds);            }            {                var queue = new ConcurrentQueue<int>();                for (int j = 0; j < 300000; j++)                {                    queue.Enqueue(j);                }                var watch = Stopwatch.StartNew();                for (int j = 0; j < 300000; j++)                {                    int value;                    queue.TryDequeue(out value);                }                watch.Stop();                Console.WriteLine("TryDequeue::ConcurrentQueue::" + watch.ElapsedMilliseconds);            }

List: Insert first: 57328 MS
MS list: Add: 8
List: removeat (0): 56700 MS


Counter list: addfirst: 34 MS
Balance list: append: 100 MS
Mirror list: removefirst: 16 MS

Queue: enqueue: MS 15
Queue: dequeue :: 10 MS

Concurrentqueue: enqueue: 138 MS
Concurrentqueue: trydequeue: 18 MS

Performance Test of list <t>, queue list <t>, queue <t>, concurrentqueue <t>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.