没有搜到别人的测试,这个项目已经不更新了,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时候,可以直接在下侧控制台中执行命令设置环境变量,之后就可以用了