17 int main(
int argc,
char* argv[])
19 int count = argc > 1 ? std::atoi(argv[1]) : 100;
20 size_t size = argc > 2 ? std::atoi(argv[2]) : 128;
22 std::cout <<
" count: " << count << std::endl
23 <<
" size: " << size <<
" bytes" << std::endl
40 char* buffer =
new char[size + 1];
42 std::memset(buffer,
'X', size + 1);
45 std::cout <<
"BasicLayout:" << std::endl;
48 for (
int i = 0; i < count; i++) log.
error(
"%s", buffer);
50 std::cout <<
" charbuf printf ostream: " << ((float)clock.
elapsed()) / count <<
" us" << std::endl;
54 const char* buffer2 = buffer;
56 for (
int i = 0; i < count; i++) log.
error(std::string(buffer2));
58 std::cout <<
" charbuf string ostream: " << ((float)clock.
elapsed()) / count <<
" us" << std::endl;
62 std::string str(size,
'X');
65 for (
int i = 0; i < count; i++)
68 std::cout <<
" string stream ostream: " << ((float)clock.
elapsed()) / count <<
" us" << std::endl;
73 for (
int i = 0; i < count; i++)
76 std::cout <<
" charbuf stream ostream: " << ((float)clock.
elapsed()) / count <<
" us" << std::endl;
80 std::string str(size,
'X');
84 for (
int i = 0; i < count; i++)
87 std::cout <<
" string stream2 ostream: " << ((float)clock.
elapsed()) / count <<
" us" << std::endl;
93 for (
int i = 0; i < count; i++)
96 std::cout <<
" charbuf stream2 ostream: " << ((float)clock.
elapsed()) / count <<
" us" << std::endl;
100 std::string str(size,
'X');
103 for (
int i = 0; i < count; i++) log.
error(str);
105 std::cout <<
" direct string ostream: " << ((float)clock.
elapsed()) / count <<
" us" << std::endl;
109 std::string str(size,
'X');
114 for (
int i = 0; i < count; i++) log.
error(str);
116 std::cout <<
" direct string file: " << ((float)clock.
elapsed()) / count <<
" us" << std::endl;
119 std::cout <<
"PatternLayout:" << std::endl;
123 ostreamAppender.
setLayout(patternLayout);
136 for (
int i = 0; i < count; i++) log.
error(
"%s", buffer);
138 std::cout <<
" charbuf printf ostream: " << ((float)clock.
elapsed()) / count <<
" us" << std::endl;
142 std::string str(size,
'X');
145 for (
int i = 0; i < count; i++) log.
error(str);
147 std::cout <<
" direct string ostream: " << ((float)clock.
elapsed()) / count <<
" us" << std::endl;
151 std::string str(size,
'X');
156 for (
int i = 0; i < count; i++) log.
error(str);
158 std::cout <<
" string file: " << ((float)clock.
elapsed()) / count <<
" us" << std::endl;
163 for (
int i = 0; i < count; i++) fprintf(stderr,
"%d ERROR someCategory : %s\n",
log4cpp::TimeStamp().getSeconds(), buffer);
165 std::cout << std::endl <<
" fprintf: " << ((float)clock.
elapsed()) / count <<
" us" << std::endl;
LOG4CPP_EXPORT CategoryStream & eol(CategoryStream &os)
int main(int argc, char *argv[])
static Category & getInstance(const std::string &name)
virtual void setConversionPattern(const std::string &conversionPattern)
virtual void removeAllAppenders()
static Category & getRoot()
usec_t elapsed(void) const
virtual void setPriority(Priority::Value priority)
virtual void setLayout(Layout *layout=NULL)
virtual void addAppender(Appender *appender)
void error(const char *stringFormat,...)