mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-18 08:22:37 +01:00
Added simple benchmark of mutex performance.
This commit is contained in:
parent
b3ed2d94b5
commit
6ec9784743
7
Foundation/samples/Benchmark/CMakeLists.txt
Normal file
7
Foundation/samples/Benchmark/CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
||||
set(SAMPLE_NAME "MutexBenchmark")
|
||||
|
||||
set(LOCAL_SRCS "")
|
||||
aux_source_directory(src LOCAL_SRCS)
|
||||
|
||||
add_executable( ${SAMPLE_NAME} ${LOCAL_SRCS} )
|
||||
target_link_libraries( ${SAMPLE_NAME} PocoFoundation )
|
72
Foundation/samples/Benchmark/src/Benchmark.cpp
Normal file
72
Foundation/samples/Benchmark/src/Benchmark.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
//
|
||||
// Benchmark.cpp
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// This sample shows a benchmark of various mutex implementations.
|
||||
//
|
||||
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
template<typename Mtx>
|
||||
void Benchmark(Mtx& mtx, std::string const& label)
|
||||
{
|
||||
Poco::Stopwatch sw;
|
||||
sw.start();
|
||||
|
||||
const int LOOP_COUNT = 100000000;
|
||||
for (int i = 0 ; i < LOOP_COUNT ; ++i)
|
||||
{
|
||||
mtx.lock();
|
||||
mtx.unlock();
|
||||
}
|
||||
|
||||
mtx.lock();
|
||||
|
||||
for (int i = 0 ; i < LOOP_COUNT ; ++i)
|
||||
{
|
||||
mtx.unlock();
|
||||
mtx.lock();
|
||||
}
|
||||
|
||||
mtx.unlock();
|
||||
|
||||
sw.stop();
|
||||
|
||||
std::cout << label << ' ' << sw.elapsed() << " [us]" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
{
|
||||
Poco::NullMutex mtx;
|
||||
Benchmark(mtx, "NullMutex");
|
||||
}
|
||||
|
||||
{
|
||||
Poco::Mutex mtx(true);
|
||||
Benchmark(mtx, "Mutex(true)");
|
||||
}
|
||||
|
||||
{
|
||||
Poco::Mutex mtx(false);
|
||||
Benchmark(mtx, "Mutex(false)");
|
||||
}
|
||||
|
||||
{
|
||||
Poco::FastMutex mtx;
|
||||
Benchmark(mtx, "FastMutex");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
add_subdirectory(ActiveMethod)
|
||||
add_subdirectory(Activity)
|
||||
add_subdirectory(Benchmark)
|
||||
add_subdirectory(BinaryReaderWriter)
|
||||
add_subdirectory(DateTime)
|
||||
add_subdirectory(LogRotation)
|
||||
|
Loading…
x
Reference in New Issue
Block a user