Added: g3log, log4cplus, log4cpp, p7. Changes: boost, easylogging, g2log, glog, spdlog.
This commit is contained in:
		
							parent
							
								
									650daf7542
								
							
						
					
					
						commit
						c83dd5d60e
					
				
							
								
								
									
										10
									
								
								bench/easyl-mt.conf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								bench/easyl-mt.conf
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					* GLOBAL:
 | 
				
			||||||
 | 
					    FORMAT                  =   "[%datetime]: %msg"
 | 
				
			||||||
 | 
					    FILENAME                =   ./logs/easylogging-mt.log
 | 
				
			||||||
 | 
					    ENABLED                 =   true
 | 
				
			||||||
 | 
					    TO_FILE                 =   true
 | 
				
			||||||
 | 
					    TO_STANDARD_OUTPUT      =   false
 | 
				
			||||||
 | 
					    MILLISECONDS_WIDTH      =   3
 | 
				
			||||||
 | 
					    PERFORMANCE_TRACKING    =   false
 | 
				
			||||||
 | 
					    MAX_LOG_FILE_SIZE       =   10485760
 | 
				
			||||||
 | 
					    Log_Flush_Threshold		= 	10485760
 | 
				
			||||||
							
								
								
									
										62
									
								
								bench/g3log-async.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								bench/g3log-async.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,62 @@
 | 
				
			|||||||
 | 
					//
 | 
				
			||||||
 | 
					// Copyright(c) 2015 Gabi Melman.
 | 
				
			||||||
 | 
					// Distributed under the MIT License (http://opensource.org/licenses/MIT)
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <atomic>
 | 
				
			||||||
 | 
					#include <chrono>
 | 
				
			||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <thread>
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "g3log/g3log.hpp"
 | 
				
			||||||
 | 
					#include "g3log/logworker.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 worker = g3::LogWorker::createLogWorker();
 | 
				
			||||||
 | 
					    auto handle= worker->addDefaultLogger(argv[0], "logs");
 | 
				
			||||||
 | 
					    g3::initializeLogging(worker.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;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										80
									
								
								bench/log4cplus-bench-mt.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								bench/log4cplus-bench-mt.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,80 @@
 | 
				
			|||||||
 | 
					//
 | 
				
			||||||
 | 
					// Copyright(c) 2015 Gabi Melman.
 | 
				
			||||||
 | 
					// Distributed under the MIT License (http://opensource.org/licenses/MIT)
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <atomic>
 | 
				
			||||||
 | 
					#include <chrono>
 | 
				
			||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <memory>
 | 
				
			||||||
 | 
					#include <thread>
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "log4cplus/logger.h"
 | 
				
			||||||
 | 
					#include "log4cplus/fileappender.h"
 | 
				
			||||||
 | 
					#include "log4cplus/layout.h"
 | 
				
			||||||
 | 
					#include "log4cplus/ndc.h"
 | 
				
			||||||
 | 
					#include "log4cplus/helpers/loglog.h"
 | 
				
			||||||
 | 
					#include "log4cplus/helpers/property.h"
 | 
				
			||||||
 | 
					#include "log4cplus/loggingmacros.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using namespace log4cplus;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int argc, char * argv[])
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    using namespace std::chrono;
 | 
				
			||||||
 | 
					    using clock = steady_clock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int thread_count = 10;
 | 
				
			||||||
 | 
					    if (argc > 1)
 | 
				
			||||||
 | 
					        thread_count = std::atoi(argv[1]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int howmany = 1000000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    log4cplus::initialize();
 | 
				
			||||||
 | 
					    SharedFileAppenderPtr append(
 | 
				
			||||||
 | 
					        new FileAppender(LOG4CPLUS_TEXT("logs/log4cplus-bench-mt.log"), std::ios_base::trunc,
 | 
				
			||||||
 | 
					            true, true));
 | 
				
			||||||
 | 
					    append->setName(LOG4CPLUS_TEXT("File"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    log4cplus::tstring pattern = LOG4CPLUS_TEXT("%d{%Y-%m-%d %H:%M:%S.%Q}: %p - %m %n");
 | 
				
			||||||
 | 
					    append->setLayout( std::auto_ptr<Layout>(new PatternLayout(pattern)) );
 | 
				
			||||||
 | 
					    append->getloc();
 | 
				
			||||||
 | 
					    Logger::getRoot().addAppender(SharedAppenderPtr(append.get()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Logger root = Logger::getRoot();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::atomic<int> msg_counter{0};
 | 
				
			||||||
 | 
					    std::vector<std::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;
 | 
				
			||||||
 | 
					                LOG4CPLUS_INFO(root, "log4cplus 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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::cout << "Total: " << howmany << std::endl;
 | 
				
			||||||
 | 
					    std::cout << "Threads: " << thread_count << std::endl;
 | 
				
			||||||
 | 
					    std::cout << "Delta = " << deltaf << " seconds" << std::endl;
 | 
				
			||||||
 | 
					    std::cout << "Rate = " << rate << "/sec" << std::endl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    log4cplus::Logger::shutdown();
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										54
									
								
								bench/log4cplus-bench.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								bench/log4cplus-bench.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,54 @@
 | 
				
			|||||||
 | 
					//
 | 
				
			||||||
 | 
					// Copyright(c) 2015 Gabi Melman.
 | 
				
			||||||
 | 
					// Distributed under the MIT License (http://opensource.org/licenses/MIT)
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <chrono>
 | 
				
			||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <memory>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "log4cplus/logger.h"
 | 
				
			||||||
 | 
					#include "log4cplus/fileappender.h"
 | 
				
			||||||
 | 
					#include "log4cplus/layout.h"
 | 
				
			||||||
 | 
					#include "log4cplus/ndc.h"
 | 
				
			||||||
 | 
					#include "log4cplus/helpers/loglog.h"
 | 
				
			||||||
 | 
					#include "log4cplus/helpers/property.h"
 | 
				
			||||||
 | 
					#include "log4cplus/loggingmacros.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using namespace log4cplus;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int, char *[])
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    using namespace std::chrono;
 | 
				
			||||||
 | 
					    using clock = steady_clock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int howmany = 1000000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    log4cplus::initialize();
 | 
				
			||||||
 | 
					    SharedFileAppenderPtr append(
 | 
				
			||||||
 | 
					        new FileAppender(LOG4CPLUS_TEXT("logs/log4cplus-bench.log"), std::ios_base::trunc,
 | 
				
			||||||
 | 
					            true, true));
 | 
				
			||||||
 | 
					    append->setName(LOG4CPLUS_TEXT("File"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    log4cplus::tstring pattern = LOG4CPLUS_TEXT("%d{%Y-%m-%d %H:%M:%S.%Q}: %p - %m %n");
 | 
				
			||||||
 | 
					    append->setLayout( std::auto_ptr<Layout>(new PatternLayout(pattern)) );
 | 
				
			||||||
 | 
					    append->getloc();
 | 
				
			||||||
 | 
					    Logger::getRoot().addAppender(SharedAppenderPtr(append.get()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Logger root = Logger::getRoot();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    auto start = clock::now();
 | 
				
			||||||
 | 
					    for (int i = 0; i < howmany; ++i)
 | 
				
			||||||
 | 
					        LOG4CPLUS_INFO(root, "log4cplus message #" << i << ": This is some text for your pleasure");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    duration<float> delta = clock::now() - start;
 | 
				
			||||||
 | 
					    float deltaf = delta.count();
 | 
				
			||||||
 | 
					    auto rate = howmany / deltaf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::cout << "Total: " << howmany << std::endl;
 | 
				
			||||||
 | 
					    std::cout << "Delta = " << deltaf << " seconds" << std::endl;
 | 
				
			||||||
 | 
					    std::cout << "Rate = " << rate << "/sec" << std::endl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    log4cplus::Logger::shutdown();
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										74
									
								
								bench/log4cpp-bench-mt.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								bench/log4cpp-bench-mt.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,74 @@
 | 
				
			|||||||
 | 
					//
 | 
				
			||||||
 | 
					// Copyright(c) 2015 Gabi Melman.
 | 
				
			||||||
 | 
					// Distributed under the MIT License (http://opensource.org/licenses/MIT)
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <atomic>
 | 
				
			||||||
 | 
					#include <chrono>
 | 
				
			||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <memory>
 | 
				
			||||||
 | 
					#include <thread>
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "log4cpp/Category.hh"
 | 
				
			||||||
 | 
					#include "log4cpp/Appender.hh"
 | 
				
			||||||
 | 
					#include "log4cpp/FileAppender.hh"
 | 
				
			||||||
 | 
					#include "log4cpp/Layout.hh"
 | 
				
			||||||
 | 
					#include "log4cpp/BasicLayout.hh"
 | 
				
			||||||
 | 
					#include "log4cpp/Priority.hh"
 | 
				
			||||||
 | 
					#include "log4cpp/PatternLayout.hh"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int argc, char * argv[])
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    using namespace std::chrono;
 | 
				
			||||||
 | 
					    using clock = steady_clock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int thread_count = 10;
 | 
				
			||||||
 | 
					    if (argc > 1)
 | 
				
			||||||
 | 
					        thread_count = std::atoi(argv[1]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int howmany = 1000000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    log4cpp::Appender *appender  = new log4cpp::FileAppender("default", "logs/log4cpp-bench-mt.log");
 | 
				
			||||||
 | 
					    log4cpp::PatternLayout *layout = new log4cpp::PatternLayout();
 | 
				
			||||||
 | 
					    layout->setConversionPattern("{%Y-%m-%d %H:%M:%S.%l}: %p - %m %n");
 | 
				
			||||||
 | 
					    appender->setLayout(layout);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    log4cpp::Category& root = log4cpp::Category::getRoot();
 | 
				
			||||||
 | 
					    root.addAppender(appender);
 | 
				
			||||||
 | 
					    root.setPriority(log4cpp::Priority::INFO);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::atomic<int> msg_counter{0};
 | 
				
			||||||
 | 
					    std::vector<std::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;
 | 
				
			||||||
 | 
					                root << log4cpp::Priority::INFO << "log4cpp 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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::cout << "Total: " << howmany << std::endl;
 | 
				
			||||||
 | 
					    std::cout << "Threads: " << thread_count << std::endl;
 | 
				
			||||||
 | 
					    std::cout << "Delta = " << deltaf << " seconds" << std::endl;
 | 
				
			||||||
 | 
					    std::cout << "Rate = " << rate << "/sec" << std::endl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    root.shutdown();
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										48
									
								
								bench/log4cpp-bench.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								bench/log4cpp-bench.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,48 @@
 | 
				
			|||||||
 | 
					//
 | 
				
			||||||
 | 
					// Copyright(c) 2015 Gabi Melman.
 | 
				
			||||||
 | 
					// Distributed under the MIT License (http://opensource.org/licenses/MIT)
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <chrono>
 | 
				
			||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <memory>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "log4cpp/Category.hh"
 | 
				
			||||||
 | 
					#include "log4cpp/Appender.hh"
 | 
				
			||||||
 | 
					#include "log4cpp/FileAppender.hh"
 | 
				
			||||||
 | 
					#include "log4cpp/Layout.hh"
 | 
				
			||||||
 | 
					#include "log4cpp/BasicLayout.hh"
 | 
				
			||||||
 | 
					#include "log4cpp/Priority.hh"
 | 
				
			||||||
 | 
					#include "log4cpp/PatternLayout.hh"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int, char *[])
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    using namespace std::chrono;
 | 
				
			||||||
 | 
					    using clock = steady_clock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int howmany = 1000000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    log4cpp::Appender *appender  = new log4cpp::FileAppender("default", "logs/log4cpp-bench.log");
 | 
				
			||||||
 | 
					    log4cpp::PatternLayout *layout = new log4cpp::PatternLayout();
 | 
				
			||||||
 | 
					    layout->setConversionPattern("%d{%Y-%m-%d %H:%M:%S.%l}: %p - %m %n");
 | 
				
			||||||
 | 
					    appender->setLayout(layout);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    log4cpp::Category& root = log4cpp::Category::getRoot();
 | 
				
			||||||
 | 
					    root.addAppender(appender);
 | 
				
			||||||
 | 
					    root.setPriority(log4cpp::Priority::INFO);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    auto start = clock::now();
 | 
				
			||||||
 | 
					    for (int i = 0; i < howmany; ++i)
 | 
				
			||||||
 | 
					        root << log4cpp::Priority::INFO << "log4cpp message #" << i << ": This is some text for your pleasure";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    duration<float> delta = clock::now() - start;
 | 
				
			||||||
 | 
					    float deltaf = delta.count();
 | 
				
			||||||
 | 
					    auto rate = howmany / deltaf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::cout << "Total: " << howmany << std::endl;
 | 
				
			||||||
 | 
					    std::cout << "Delta = " << deltaf << " seconds" << std::endl;
 | 
				
			||||||
 | 
					    std::cout << "Rate = " << rate << "/sec" << std::endl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    root.shutdown();
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										97
									
								
								bench/p7-bench-mt.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								bench/p7-bench-mt.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,97 @@
 | 
				
			|||||||
 | 
					//
 | 
				
			||||||
 | 
					// Copyright(c) 2015 Gabi Melman.
 | 
				
			||||||
 | 
					// Distributed under the MIT License (http://opensource.org/licenses/MIT)
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <atomic>
 | 
				
			||||||
 | 
					#include <chrono>
 | 
				
			||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <thread>
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					#include <memory>
 | 
				
			||||||
 | 
					#include <functional>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "P7_Trace.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int argc, char *argv[])
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    using namespace std::chrono;
 | 
				
			||||||
 | 
					    using clock = steady_clock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int thread_count = 10;
 | 
				
			||||||
 | 
					    if (argc > 1)
 | 
				
			||||||
 | 
					        thread_count = std::atoi(argv[1]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int howmany = 1000000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    IP7_Trace::hModule module = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //create P7 client object
 | 
				
			||||||
 | 
					    std::unique_ptr<IP7_Client, std::function<void (IP7_Client *)>> client(
 | 
				
			||||||
 | 
					        P7_Create_Client(TM("/P7.Pool=1024 /P7.Sink=FileTxt /P7.Dir=logs/p7-bench-mt")),
 | 
				
			||||||
 | 
					        [&](IP7_Client *ptr){
 | 
				
			||||||
 | 
					            if (ptr)
 | 
				
			||||||
 | 
					                ptr->Release();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!client)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        std::cout << "Can't create IP7_Client" << std::endl;
 | 
				
			||||||
 | 
					        return 1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //create P7 trace object 1
 | 
				
			||||||
 | 
					    std::unique_ptr<IP7_Trace, std::function<void (IP7_Trace *)>> trace(
 | 
				
			||||||
 | 
					        P7_Create_Trace(client.get(), TM("Trace channel 1")),
 | 
				
			||||||
 | 
					        [&](IP7_Trace *ptr){
 | 
				
			||||||
 | 
					            if (ptr)
 | 
				
			||||||
 | 
					                ptr->Release();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!trace)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        std::cout << "Can't create IP7_Trace" << std::endl;
 | 
				
			||||||
 | 
					        return 1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    trace->Register_Thread(TM("Application"), 0);
 | 
				
			||||||
 | 
					    trace->Register_Module(TM("Main"), &module);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::atomic<int> msg_counter{0};
 | 
				
			||||||
 | 
					    std::vector<std::thread> threads;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    auto start = clock::now();
 | 
				
			||||||
 | 
					    for (int t = 0; t < thread_count; ++t)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        threads.push_back(std::thread([&]() {
 | 
				
			||||||
 | 
					            trace->Register_Thread(TM("Application"), t+1);
 | 
				
			||||||
 | 
					            while (true)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                int counter = ++msg_counter;
 | 
				
			||||||
 | 
					                if (counter > howmany)
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                trace->P7_INFO(module, TM("p7 message #%d: This is some text for your pleasure"), counter);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            trace->Register_Thread(TM("Application"), t+1);
 | 
				
			||||||
 | 
					        }));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (auto &t : threads)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        t.join();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    duration<float> delta = clock::now() - start;
 | 
				
			||||||
 | 
					    float deltaf = delta.count();
 | 
				
			||||||
 | 
					    auto rate = howmany / deltaf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::cout << "Total: " << howmany << std::endl;
 | 
				
			||||||
 | 
					    std::cout << "Threads: " << thread_count << std::endl;
 | 
				
			||||||
 | 
					    std::cout << "Delta = " << deltaf << " seconds" << std::endl;
 | 
				
			||||||
 | 
					    std::cout << "Rate = " << rate << "/sec" << std::endl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    trace->Unregister_Thread(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										70
									
								
								bench/p7-bench.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								bench/p7-bench.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,70 @@
 | 
				
			|||||||
 | 
					//
 | 
				
			||||||
 | 
					// Copyright(c) 2015 Gabi Melman.
 | 
				
			||||||
 | 
					// Distributed under the MIT License (http://opensource.org/licenses/MIT)
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <chrono>
 | 
				
			||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <memory>
 | 
				
			||||||
 | 
					#include <functional>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "P7_Trace.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int, char *[])
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    using namespace std::chrono;
 | 
				
			||||||
 | 
					    using clock = steady_clock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int howmany = 1000000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    IP7_Trace::hModule module = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //create P7 client object
 | 
				
			||||||
 | 
					    std::unique_ptr<IP7_Client, std::function<void (IP7_Client *)>> client(
 | 
				
			||||||
 | 
					        P7_Create_Client(TM("/P7.Pool=1024 /P7.Sink=FileTxt /P7.Dir=logs/p7-bench")),
 | 
				
			||||||
 | 
					        [&](IP7_Client *ptr){
 | 
				
			||||||
 | 
					            if (ptr)
 | 
				
			||||||
 | 
					                ptr->Release();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!client)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        std::cout << "Can't create IP7_Client" << std::endl;
 | 
				
			||||||
 | 
					        return 1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //create P7 trace object 1
 | 
				
			||||||
 | 
					    std::unique_ptr<IP7_Trace, std::function<void (IP7_Trace *)>> trace(
 | 
				
			||||||
 | 
					        P7_Create_Trace(client.get(), TM("Trace channel 1")),
 | 
				
			||||||
 | 
					        [&](IP7_Trace *ptr){
 | 
				
			||||||
 | 
					            if (ptr)
 | 
				
			||||||
 | 
					                ptr->Release();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!trace)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        std::cout << "Can't create IP7_Trace" << std::endl;
 | 
				
			||||||
 | 
					        return 1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    trace->Register_Thread(TM("Application"), 0);
 | 
				
			||||||
 | 
					    trace->Register_Module(TM("Main"), &module);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    auto start = clock::now();
 | 
				
			||||||
 | 
					    for (int i = 0; i < howmany; ++i)
 | 
				
			||||||
 | 
					        trace->P7_INFO(module, TM("p7 message #%d: This is some text for your pleasure"), i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    duration<float> delta = clock::now() - start;
 | 
				
			||||||
 | 
					    float deltaf = delta.count();
 | 
				
			||||||
 | 
					    auto rate = howmany / deltaf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::cout << "Total: " << howmany << std::endl;
 | 
				
			||||||
 | 
					    std::cout << "Delta = " << deltaf << " seconds" << std::endl;
 | 
				
			||||||
 | 
					    std::cout << "Rate = " << rate << "/sec" << std::endl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    trace->Unregister_Thread(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user