A performance comparison among data structures in concurrent programming

This document is about a performance comparison among a number data structures in concurrent programming.
Tests environment: 1 – 4 threads on Ubuntu20

Tested data structures:

  1. integer counter (simple C integer variable counter) [1]
  2. Queue ( C structure – user defined queue data type) [2]
  3. Stack (C++ class object std::stack) [3]
  4. list (C++ non class – std::list is used) [3]
  5. linked list (C pointer structure – user defined queue data type)[1]

Test subject:
Use a loop of 1 million times to add a number in all kinds of the data structures in a concurrent fashion and meanwhile, to count the time taken.
To integer number, we have a integer variable, count from 0 to 1 million. The threads we tested are from 1 to 4.

Results:

A performance comparison among data structures in concurrent programming

Conclusion:
Based on the result, we came to following understanding:

  1. Simple data type or structure costs less time than complex data structure.

  2. Programs written in C costs less time than programs written in C++.

  3. When threads number increased, the scale issue does happen on each data type or structures.

  4. In term of C++ programs:
    A. non-class programming has more costs of time than class used programming.
    B. When threads increased from 1 to 2, the time taken seems to have a spike. It is strange to see that when threads increased to 3, the time taken decreased significantly comparing with 2 threads used. When threads increased to 4, the average time taken is less than 2 threads used on average.

    References:
    [1] R. Arpaci-Dusseau and A. Arpaci-Dusseau, “Lock-Based Concurrent Data Structures,” in Operating Systems: Three Easy Pieces, Chapter 29, p. 9: https://pages.cs.wisc.edu/~remzi/OSTEP/threads-locks-usage.pdf.
    [2] W. Herlihy and N. Shavit, The Art of Multiprocessor Programming Second edition(Morgan Kaufmann, 2021).
    [3] A NTHONY W ILLIAMS, C++ Concurrency in Action Second Edition

上一篇:orb_slam2和3安装


下一篇:Bezos写给股东的信