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.

110 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. PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("log4cplus.properties"));
  21. Logger root = Logger::getRoot();
  22. try {
  23. Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("testlogger"));
  24. LOG4CPLUS_WARN(Logger::getRoot (), "Starting test loop....");
  25. Time start = Time::gettimeofday();
  26. tstring msg(LOG4CPLUS_TEXT("This is a WARNING..."));
  27. int i = 0;
  28. for(i=0; i<LOOP_COUNT; ++i) {
  29. LOG4CPLUS_WARN(logger, msg);
  30. }
  31. Time end = Time::gettimeofday();
  32. Time diff = end - start;
  33. LOG4CPLUS_WARN(LOG4CPLUS_TEXT("root"), "Logging " << LOOP_COUNT << " took: " << diff << endl);
  34. LOG4CPLUS_WARN(root, "Logging average: " << (diff/LOOP_COUNT) << endl);
  35. start = Time::gettimeofday();
  36. for(i=0; i<LOOP_COUNT; ++i) {
  37. tostringstream buffer;
  38. buffer /*<< "test"*/ << 123122;
  39. tstring tmp = buffer.str();
  40. }
  41. end = Time::gettimeofday();
  42. diff = end - start;
  43. LOG4CPLUS_WARN(root, "tostringstream average: " << (diff/LOOP_COUNT) << endl);
  44. start = Time::gettimeofday();
  45. for(i=0; i<LOOP_COUNT; ++i) {
  46. log4cplus::spi::InternalLoggingEvent e(logger.getName(), log4cplus::WARN_LOG_LEVEL,
  47. msg, 0, 0);
  48. }
  49. end = Time::gettimeofday();
  50. diff = end - start;
  51. LOG4CPLUS_WARN(root, "Creating log " << LOOP_COUNT << " objects took: " << diff);
  52. LOG4CPLUS_WARN(root, "Creating log object average: " << (diff/LOOP_COUNT) << endl);
  53. start = Time::gettimeofday();
  54. for(i=0; i<LOOP_COUNT; ++i) {
  55. log4cplus::spi::InternalLoggingEvent e(logger.getName(), log4cplus::WARN_LOG_LEVEL,
  56. msg, 0, 0);
  57. e.getNDC();
  58. e.getThread();
  59. }
  60. end = Time::gettimeofday();
  61. diff = end - start;
  62. LOG4CPLUS_WARN(root, "Creating FULL log " << LOOP_COUNT << " objects took: " << diff);
  63. LOG4CPLUS_WARN(root, "Creating FULL log object average: " << (diff/LOOP_COUNT) << endl);
  64. start = Time::gettimeofday();
  65. for(i=0; i<LOOP_COUNT; ++i) {
  66. log4cplus::spi::InternalLoggingEvent e(logger.getName(), log4cplus::WARN_LOG_LEVEL,
  67. msg, 0, 0);
  68. e.getNDC();
  69. }
  70. end = Time::gettimeofday();
  71. diff = end - start;
  72. LOG4CPLUS_WARN(root, "getNDC() " << LOOP_COUNT << " calls took: " << diff);
  73. LOG4CPLUS_WARN(root, "getNDC() average: " << (diff/LOOP_COUNT) << endl);
  74. start = Time::gettimeofday();
  75. for(i=0; i<LOOP_COUNT; ++i) {
  76. log4cplus::spi::InternalLoggingEvent e(logger.getName(), log4cplus::WARN_LOG_LEVEL,
  77. msg, 0, 0);
  78. e.getThread();
  79. }
  80. end = Time::gettimeofday();
  81. diff = end - start;
  82. LOG4CPLUS_WARN(root, "getThread() " << LOOP_COUNT << " calls took: " << diff);
  83. LOG4CPLUS_WARN(root, "getThread() average: " << (diff/LOOP_COUNT) << endl);
  84. }
  85. catch(...) {
  86. tcout << LOG4CPLUS_TEXT("Exception...") << endl;
  87. LOG4CPLUS_FATAL(root, "Exception occured...");
  88. }
  89. tcout << LOG4CPLUS_TEXT("Exiting main()...") << endl;
  90. log4cplus::Logger::shutdown();
  91. return 0;
  92. }