You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.8 KiB

  1. #include <log4cplus/logger.h>
  2. #include <log4cplus/loggingmacros.h>
  3. #include <log4cplus/configurator.h>
  4. #include <log4cplus/helpers/loglog.h>
  5. #include <log4cplus/helpers/stringhelper.h>
  6. #include <log4cplus/helpers/timehelper.h>
  7. #include <log4cplus/spi/loggingevent.h>
  8. using namespace std;
  9. using namespace log4cplus;
  10. using namespace log4cplus::helpers;
  11. log4cplus::tostream& operator <<(log4cplus::tostream& s, const Time& t)
  12. {
  13. return s << t.sec() << "sec " << t.usec() << "usec";
  14. }
  15. #define LOOP_COUNT 100000
  16. int
  17. main()
  18. {
  19. tcout << LOG4CPLUS_TEXT("Entering main()...") << endl;
  20. log4cplus::initialize ();
  21. PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("log4cplus.properties"));
  22. Logger root = Logger::getRoot();
  23. try {
  24. Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("testlogger"));
  25. LOG4CPLUS_WARN(Logger::getRoot (), "Starting test loop....");
  26. Time start = Time::gettimeofday();
  27. tstring msg(LOG4CPLUS_TEXT("This is a WARNING..."));
  28. int i = 0;
  29. for(i=0; i<LOOP_COUNT; ++i) {
  30. LOG4CPLUS_WARN(logger, msg);
  31. }
  32. Time end = Time::gettimeofday();
  33. Time diff = end - start;
  34. LOG4CPLUS_WARN(LOG4CPLUS_TEXT("root"), "Logging " << LOOP_COUNT << " took: " << diff << endl);
  35. LOG4CPLUS_WARN(root, "Logging average: " << (diff/LOOP_COUNT) << endl);
  36. start = Time::gettimeofday();
  37. for(i=0; i<LOOP_COUNT; ++i) {
  38. tostringstream buffer;
  39. buffer /*<< "test"*/ << 123122;
  40. tstring tmp = buffer.str();
  41. }
  42. end = Time::gettimeofday();
  43. diff = end - start;
  44. LOG4CPLUS_WARN(root, "tostringstream average: " << (diff/LOOP_COUNT) << endl);
  45. start = Time::gettimeofday();
  46. for(i=0; i<LOOP_COUNT; ++i) {
  47. log4cplus::spi::InternalLoggingEvent e(logger.getName(), log4cplus::WARN_LOG_LEVEL,
  48. msg, 0, 0);
  49. }
  50. end = Time::gettimeofday();
  51. diff = end - start;
  52. LOG4CPLUS_WARN(root, "Creating log " << LOOP_COUNT << " objects took: " << diff);
  53. LOG4CPLUS_WARN(root, "Creating log object average: " << (diff/LOOP_COUNT) << endl);
  54. start = Time::gettimeofday();
  55. for(i=0; i<LOOP_COUNT; ++i) {
  56. log4cplus::spi::InternalLoggingEvent e(logger.getName(), log4cplus::WARN_LOG_LEVEL,
  57. msg, 0, 0);
  58. e.getNDC();
  59. e.getThread();
  60. }
  61. end = Time::gettimeofday();
  62. diff = end - start;
  63. LOG4CPLUS_WARN(root, "Creating FULL log " << LOOP_COUNT << " objects took: " << diff);
  64. LOG4CPLUS_WARN(root, "Creating FULL log object average: " << (diff/LOOP_COUNT) << endl);
  65. start = Time::gettimeofday();
  66. for(i=0; i<LOOP_COUNT; ++i) {
  67. log4cplus::spi::InternalLoggingEvent e(logger.getName(), log4cplus::WARN_LOG_LEVEL,
  68. msg, 0, 0);
  69. e.getNDC();
  70. }
  71. end = Time::gettimeofday();
  72. diff = end - start;
  73. LOG4CPLUS_WARN(root, "getNDC() " << LOOP_COUNT << " calls took: " << diff);
  74. LOG4CPLUS_WARN(root, "getNDC() average: " << (diff/LOOP_COUNT) << endl);
  75. start = Time::gettimeofday();
  76. for(i=0; i<LOOP_COUNT; ++i) {
  77. log4cplus::spi::InternalLoggingEvent e(logger.getName(), log4cplus::WARN_LOG_LEVEL,
  78. msg, 0, 0);
  79. e.getThread();
  80. }
  81. end = Time::gettimeofday();
  82. diff = end - start;
  83. LOG4CPLUS_WARN(root, "getThread() " << LOOP_COUNT << " calls took: " << diff);
  84. LOG4CPLUS_WARN(root, "getThread() average: " << (diff/LOOP_COUNT) << endl);
  85. }
  86. catch(...) {
  87. tcout << LOG4CPLUS_TEXT("Exception...") << endl;
  88. LOG4CPLUS_FATAL(root, "Exception occured...");
  89. }
  90. tcout << LOG4CPLUS_TEXT("Exiting main()...") << endl;
  91. log4cplus::Logger::shutdown();
  92. return 0;
  93. }