PPL Container Performance

I am writing a server application that takes data from several sources at once and stores it in its internal database (currently std::set ).

I just looked at Microsoft ConcRT PPL data structures and wondered how their performance is compared using the fine-grained mutex on std::unordered_set . For example, there is a big performance difference between two pieces of code:

 void StdWithMutex( void ) { std::ofstream outFile( "Test.tmp" ); std::lock_guard<std::mutex> lockGuard( m_mutex ); // Iterate through the data and write it to a file: // m_setData is of type std::unordered_set<DataType> for( auto data : m_setData ) { outFile << data; } } 

and

 void ConcRT( void ) { std::ofstream outFile( "Test.tmp" ); // Iterate through the data and write it to a file: // m_setData is of type concurrency::concurrent_unordered_set for( auto data : m_setData ) { outFile << data; } } 

Moveover, I often have to print data in order, so I use std::set as opposed to std::unordered_set , so if there is an advantage in using concurrency::concurrent_unordered_set , the potential performance gain comes close to the cost of reordering the data every time it need to print?

+6
source share
1 answer

Yes, there is a huge difference. Try to start 100 threads in parallel with writing and reading from this container, and you will see the difference.

PPL container is not blocked → it will be faster (it is probably too long, or use an improved dispenser, while STL is not an exception if you specified this dispenser)

In a single thread, although it is possible that the overhead of blocking is less than that of a PPL container.

(in the same idea, a parallel queue of coost or parallel TBB containers (intel) will be faster than STL containers that can block)

+1
source

Source: https://habr.com/ru/post/947488/


All Articles