天天看點

log4cpp性能測試

沒有搜到别人的測試,這個項目已經不更新了,http://log4cpp.sourceforge.net/

自己測試一下性能:

1)window10 + vs2017: 4個線程,每個線程10000條資料,debug共1.7秒 release 0.46秒

2)window10 + vs2017:1線程40000條,debug是1.6秒;release 0.375秒

3)ubuntu18.04 虛拟機: 4個線程,每個線程10000條資料,共0.4秒

3)ubuntu18.04 虛拟機: 1個線程,每個線程40000條資料,共0.145秒

#include <iostream>
#include "Mylog.h"
#include "Timer.h"
#include <thread>
#include <vector>

#pragma comment(lib, "log4cppD.lib")
using namespace  robin;
using namespace  std;

void workerlog(int i)
{
	std::ostringstream os;
	os << "線程" << i;
	os << "hello,world!--------------------------------------------------------------------------------------";
	string str =  os.str();
	for (int i = 0; i < 10000; i++)
	{
		LOG_ERROR(str.c_str());
		//LOG_WARN("hello,world");
		//LOG_INFO("hello,world");
		//LOG_DEBUG("hello,world");
	}
}

int main()
{
	Timer timer;
	std::vector<thread> vec;
	
	timer.start();
	for (int i = 0; i < 4; i++)
	{
		vec.emplace_back<thread>(thread(workerlog, i + 1));
	}
	for (size_t i = 0; i < vec.size(); i++)
	{
		if (vec[i].joinable())
			vec[i].join();
	}

	
	double t = timer.stop_delta<Timer::ms>();
	cout << t << endl;
	

    std::cout << "Hello World!\n";
}
           
void  testLog2()
{
	timer.start();
for (int i = 0; i < 10000; i++)
	{
		LOG_ERROR("hello,world!--------------------------------------------------------------------------------------");
		LOG_WARN("hello,world!--------------------------------------------------------------------------------------");
		LOG_INFO("hello,world!--------------------------------------------------------------------------------------");
		LOG_DEBUG("hello,world!--------------------------------------------------------------------------------------");
	}
		double t = timer.stop_delta<Timer::ms>();
		cout << "使用時間 " << t << endl;
}
           

備注

vs2017編譯:

直接打開msvc10下的解決方案,編譯出來的是靜态的 lib

ubuntu編譯:

如下指令需要在root權限下執行

1、.

本地編譯:/configure --prefix=<location>   --with-pthreads

交叉編譯:./configure CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ --host=aarch64-linux-gnu --prefix=/home/xxx/code/log4cpp/log4cpp_src/log4cpp-1.1.3/log4cpp --with-pthreads

安裝完成後,log4cpp.so庫預設在/usr/local/lib下,頭檔案在/usr/local/include目錄下。

可通過該配置項修改為<location>所描述的位置。

※在使用log4cpp自帶的config.sub和config.guess檔案交叉編譯時可能會存在某些平台不能識别,此時需要使用三方的config檔案。

① apt-get install libtool

将libtool目錄下的config.guess和config.sub拷貝到log4cpp的config目錄下:

② cp /usr/share/libtool/build-aux/config.guess /usr/share/libtool/build-aux/config.sub ./log4cpp-1.1.3/log4cpp/config

2、make

3、make check

4、make install

在程式運作時,依賴的動态庫需要在執行時加入環境變量:

export LD_LIBRARY_PATH=/usr/local/lib
           

使用vscode時候,可以直接在下側控制台中執行指令設定環境變量,之後就可以用了

繼續閱讀