Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9064965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:23:13+00:00 2026-06-16T16:23:13+00:00

Upon wrapping logging into a separate class, we experienced an increase in performance which

  • 0

Upon wrapping logging into a separate class, we experienced an increase in performance which we cant quite explain.

If anyone could perhaps comment to help us make sense of this?

Here is the main thread:

package myapp;

import myapp.logging.Log;

import org.apache.log4j.Logger;

public class ApplicationMain extends Thread {
private static Logger LOG = Logger.getLogger(ApplicationMain.class); 

@Override 
public void run() {
for (int i = 0; i < 50; i++) {
    try {
    Thread.sleep(500);

    //traditional plain log4j
    long startTime = System.nanoTime();
    LOG.info("Hello World Log4j");
    long endTime = System.nanoTime();
    System.out.println(endTime - startTime);

    //logging in wrapper
    long startTime2 = System.nanoTime();
    Log.Info("Hello World Log4J from within wrapper");
    long endTime2 = System.nanoTime();
    System.out.println(endTime2 - startTime2);

    } catch (InterruptedException ex) {
    Log.Info(ex.getMessage());
    }
}
}

}

the logging wrapper class:

package myapp.logging;

import org.apache.log4j.Logger;

public class Log {


private static Logger LOG;

public static synchronized void Info(String LogMessage) {

Throwable throwable = new Throwable();
StackTraceElement[] stackTraceElements = throwable.getStackTrace();
LOG = Logger.getLogger(stackTraceElements[1].getClassName());
LOG.info(LogMessage);
}
}

Upon Thread.start() we get the following kind of output:

2013-01-02 10:42:25,359 INFO   [ApplicationMain] Hello World Log4j

191478

2013-01-02 10:42:25,359 INFO   [ApplicationMain] Hello World Log4J from within wrapper 

163852

2013-01-02 10:42:25,859 INFO   [ApplicationMain] Hello World Log4j 

166165

2013-01-02 10:42:25,859 INFO   [ApplicationMain] Hello World Log4J from within wrapper 

85361

2013-01-02 10:42:26,359 INFO   [ApplicationMain] Hello World Log4j 

188694

2013-01-02 10:42:26,359 INFO   [ApplicationMain] Hello World Log4J from within wrapper

82709

.....

Why is the wrapper out-performing the straight call? And this despite the added overhead of retrieving the caller-class name?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:23:15+00:00Added an answer on June 16, 2026 at 4:23 pm

    I would strongly reccommend reading up on micro benchmarks. This is a really interesting subject and I found this question useful as a starting point:

    How do I write a correct micro-benchmark in Java?

    Essentially this is not a valid measure of performance as there are a whole heap of other things to take into consideration mainly around compiler optimisation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Upon analysis, IntelliJ finds unused methods, but i need to be in the class
Upon initialization, GDI+ (non .NET) creates a background thread, which can optionally be suppressed
Upon upgrading to Ubuntu 10.10 on our dev machine we run into a small
upon being asked about subscribing to hardcopy periodicals concerning Macintosh development, I could only
Wrapping a struct or class field in a property forces all accesses to that
I have stumbled upon an error for which I cannot grasp the reason. I
Upon reaching a brick wall with the .Net framework's lack of a BigInteger class
I'm wrapping some C++ code with JNI, and stumbled upon the following factory function:
I am having trouble wrapping my head around the spark skin class in relation
I have a utility class with some static methods which I use in some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.