Added simple benchmark of mutex performance.

This commit is contained in:
Martin Osborne 2014-11-05 17:08:36 +00:00
parent b3ed2d94b5
commit 6ec9784743
3 changed files with 80 additions and 0 deletions

View 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 )

View 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;
}

View File

@ -1,5 +1,6 @@
add_subdirectory(ActiveMethod)
add_subdirectory(Activity)
add_subdirectory(Benchmark)
add_subdirectory(BinaryReaderWriter)
add_subdirectory(DateTime)
add_subdirectory(LogRotation)