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:
- integer counter (simple C integer variable counter) [1]
- Queue ( C structure – user defined queue data type) [2]
- Stack (C++ class object std::stack
) [3] - list (C++ non class – std::list is used) [3]
- 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:
Conclusion:
Based on the result, we came to following understanding:
-
Simple data type or structure costs less time than complex data structure.
-
Programs written in C costs less time than programs written in C++.
-
When threads number increased, the scale issue does happen on each data type or structures.
-
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