-
Notifications
You must be signed in to change notification settings - Fork 0
Mutex speed tests
// clang++-4.0 -o main main.cpp -O3 -std=c++14 -lboost_system -lboost_thread -lpthread && ./main
#include <mutex>
#include <shared_mutex>
#include <chrono>
#include <iostream>
#include <thread>
#include <boost/thread/shared_mutex.hpp>
void escape(void* p) {
asm volatile("" : : "g"(p) : "memory");
}
template <typename F>
void test(F &&fun) {
auto start = std::chrono::steady_clock::now();
for (int i = 0; i < 10000000; i++) {
fun();
}
auto end = std::chrono::steady_clock::now();
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
std::cout << ms << '\n';
}
int main() {
std::cout << "BOOST shared mutex\n";
std::cout << "lock shared\n";
boost::shared_mutex shared_mtx;
test([&shared_mtx]{
shared_mtx.lock_shared();
shared_mtx.unlock_shared();
});
std::cout << "lock\n";
test([&shared_mtx]{
shared_mtx.lock();
shared_mtx.unlock();
});
std::cout << "STD mutex\n";
std::cout << "lock\n";
std::mutex mtx;
test([&mtx]{
mtx.lock();
mtx.unlock();
});
std::cout << "STD shared_timed_mutex\n";
std::cout << "lock\n";
std::shared_timed_mutex st_mtx;
test([&st_mtx]{
st_mtx.lock();
st_mtx.unlock();
});
std::cout << "lock shared\n";
test([&st_mtx]{
st_mtx.lock_shared();
st_mtx.unlock_shared();
});
}
Object type | Operation | Time |
---|---|---|
std::mutex | lock() + unlock() | 296 |
std::shared_timed_mutex | lock() + unlock() | 447 |
boost::shared_mutex | lock() + unlock() | 1556 |
std::shared_timed_mutex | lock_shared() + unlock_shared() | 491 |
boost::shared_mutex | lock_shared() + unlock_shared() | 1587 |
Unofficial R&D page for Yedino and it's OpenSource community.
Code here can be 🚨insecure🚨 so run it only on isolated test machines/accounts.
Official Yedino is instead on https://github.com/yedino/galaxy42 .
Home || Contact || Tips❤️ || TestNr🔬 || EditWiki
Progress:
Report (blog)
Research / Current topic:
NetworkSpeed
TestNetwork10gNet1 Network
TestDevicesNX3031_HP NIC Device
NetworkSpeed10Gb 10 GB speed
Development:
GUI
Yedino Users:
YedinoServices - use this services
YedinoPeers - peer to this
Cool - most popular services
Please help
Help
NetworkSpeed 🏗️Help🏗️
Use/search emojis icons:
🏗️ - help needed
📓 - testing/lab needed
🥇 - best result (in our program)
🥈 - best result
🚫 - warning (e.g. in test results)
🚩 - interesting (e.g. in test results)
📚 - high quality resource
🚧 - todo
🚨 - warning