Revert "CMake script improvements"

This commit is contained in:
Gabi Melman
2016-05-05 10:19:32 +03:00
parent 14dd584c0b
commit 6d5bce46f8
19 changed files with 25 additions and 291 deletions

View File

@@ -1,73 +0,0 @@
#
# Benchmarks against various logging systems
#
#
# Dependencies
#
find_package(Threads)
enable_testing()
# Helper function for building benchmark programs
function(add_benchmark _target)
set(options "") # no options
set(singleValueArgs "") # no single-value arguments
set(multiValueArgs LIBS SOURCES INCLUDES DEFINITIONS) # lists of additional libraries, source files, and include directories
cmake_parse_arguments(_benchmark "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN})
add_executable(${_target} ${_target}.cpp ${_benchmark_SOURCES})
target_include_directories(
${_target}
PUBLIC
${HEADER_BASE}
${_benchmark_INCLUDES}
)
target_link_libraries(
${_target}
${CMAKE_THREAD_LIBS_INIT}
${_benchmark_LIBS}
)
if(_benchmark_DEFINITIONS)
target_compile_definitions(${_target} PUBLIC ${_benchmark_DEFINITIONS})
endif()
add_test(NAME test_benchmark_${_target} COMMAND ${_target})
endfunction()
# Benchmark programs
add_benchmark(spdlog-bench)
add_benchmark(spdlog-bench-mt)
add_benchmark(spdlog-async)
if(TARGET zf_log)
add_benchmark(zf_log-bench LIBS zf_log)
add_benchmark(zf_log-bench-mt LIBS zf_log)
endif()
find_package(Boost QUIET COMPONENTS log)
if(Boost_FOUND)
set(BOOST_DEFS "-DBOOST_LOG_DYN_LINK=1")
add_benchmark(boost-bench LIBS ${Boost_LIBRARIES} INCLUDES ${Boost_INCLUDE_DIRS} DEFINITIONS ${BOOST_DEFS})
add_benchmark(boost-bench-mt LIBS ${Boost_LIBRARIES} INCLUDES ${Boost_INCLUDE_DIRS} DEFINITIONS ${BOOST_DEFS})
endif()
if(TARGET glog)
add_benchmark(glog-bench LIBS glog)
add_benchmark(glog-bench-mt LIBS glog)
endif()
if(TARGET g3logger)
add_benchmark(g3log-async LIBS g3logger INCLUDES "${g3log_SOURCE_DIR}/src")
endif()
if(TARGET easylogging)
add_benchmark(easylogging-bench LIBS easylogging)
add_benchmark(easylogging-bench-mt LIBS easylogging)
endif()
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs")

View File

@@ -9,7 +9,7 @@
#define _ELPP_THREAD_SAFE
#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP
_INITIALIZE_EASYLOGGINGPP
using namespace std;

View File

@@ -6,7 +6,7 @@
#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP
_INITIALIZE_EASYLOGGINGPP
int main(int, char* [])
{

View File

@@ -1,63 +0,0 @@
//
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
#include <thread>
#include <vector>
#include <atomic>
#include <iostream>
#include <chrono>
#include <g3log/logworker.hpp>
#include <g3log/g3log.hpp>
using namespace std;
template<typename T> std::string format(const T& value);
int main(int argc, char* argv[])
{
using namespace std::chrono;
using clock=steady_clock;
int thread_count = 10;
if(argc > 1)
thread_count = atoi(argv[1]);
int howmany = 1000000;
auto g3log = g3::LogWorker::createLogWorker();
auto defaultHandler = g3log->addDefaultLogger(argv[0], "logs");
g3::initializeLogging(g3log.get());
std::atomic<int > msg_counter {0};
vector<thread> threads;
auto start = clock::now();
for (int t = 0; t < thread_count; ++t)
{
threads.push_back(std::thread([&]()
{
while (true)
{
int counter = ++msg_counter;
if (counter > howmany) break;
LOG(INFO) << "g3log message #" << counter << ": This is some text for your pleasure";
}
}));
}
for(auto &t:threads)
{
t.join();
};
duration<float> delta = clock::now() - start;
float deltaf = delta.count();
auto rate = howmany/deltaf;
cout << "Total: " << howmany << std::endl;
cout << "Threads: " << thread_count << std::endl;
std::cout << "Delta = " << deltaf << " seconds" << std::endl;
std::cout << "Rate = " << rate << "/sec" << std::endl;
}

View File

@@ -9,7 +9,7 @@
const char g_path[] = "logs/zf_log.txt";
int g_fd;
static void output_callback(const zf_log_message* msg, void* arg)
static void output_callback(zf_log_message *msg)
{
*msg->p = '\n';
write(g_fd, msg->buf, msg->p - msg->buf + 1);
@@ -25,7 +25,7 @@ int main(int argc, char* argv[])
ZF_LOGE_AUX(ZF_LOG_STDERR, "Failed to open log file: %s", g_path);
return -1;
}
ZF_LOG_DEFINE_GLOBAL_OUTPUT = {ZF_LOG_PUT_STD, nullptr, &output_callback};
zf_log_set_output_callback(ZF_LOG_PUT_STD, output_callback);
int thread_count = 10;
if(argc > 1)

View File

@@ -4,7 +4,7 @@
const char g_path[] = "logs/zf_log.txt";
static FILE *g_f;
static void output_callback(const zf_log_message* msg, void* arg)
static void output_callback(zf_log_message *msg)
{
*msg->p = '\n';
fwrite(msg->buf, msg->p - msg->buf + 1, 1, g_f);
@@ -18,7 +18,7 @@ int main(int, char* [])
ZF_LOGE_AUX(ZF_LOG_STDERR, "Failed to open log file: %s", g_path);
return -1;
}
ZF_LOG_DEFINE_GLOBAL_OUTPUT = {ZF_LOG_PUT_STD, nullptr, &output_callback};
zf_log_set_output_callback(ZF_LOG_PUT_STD, output_callback);
const int howmany = 1000000;
for(int i = 0 ; i < howmany; ++i)