On Sat, 2005-01-22 at 10:41, Ceki GÃlcà wrote:
> Hi Elias,
> 
> I had a cursory look at the code. It looks pretty good.
> 
> Although it may be my suggestion to begin with, comparing
...

That's what you asked for from your original...

You can run the other test you want.

Anyway, if you wanted results, they're are pretty much the same. 
They're so much variation as it's sort of up the the whim of the thread
scheduler who wins.

     [java] Appender class org.apache.log4j.concurrent.FileAppender
     [java] Took 1630ms for 1000 logs *  threads 5
 
     [java] Appender class org.apache.log4j.FileAppender
     [java] Took 1283ms for 1000 logs *  threads 5
 
     [java] Appender class org.apache.log4j.concurrent.FileAppender
     [java] Took 1336ms for 1000 logs *  threads 5
 
     [java] Appender class org.apache.log4j.FileAppender
     [java] Took 1566ms for 1000 logs *  threads 5
 
     [java] Appender class org.apache.log4j.concurrent.FileAppender
     [java] Took 1183ms for 1000 logs *  threads 5
 
     [java] Appender class org.apache.log4j.FileAppender
     [java] Took 1196ms for 1000 logs *  threads 5

Not impressed?  On a two CPU machine things look a little better for the
concurrent version:

     [java] Appender class org.apache.log4j.FileAppender
     [java] Took 24983ms for 100000 logs *  threads 4
 
     [java] Appender class org.apache.log4j.concurrent.FileAppender
     [java] Took 23906ms for 100000 logs *  threads 4
 
     [java] Appender class org.apache.log4j.FileAppender
     [java] Took 24613ms for 100000 logs *  threads 4
 
     [java] Appender class org.apache.log4j.concurrent.FileAppender
     [java] Took 23080ms for 100000 logs *  threads 4
 
     [java] Appender class org.apache.log4j.FileAppender
     [java] Took 24668ms for 100000 logs *  threads 4
 
     [java] Appender class org.apache.log4j.concurrent.FileAppender
     [java] Took 23827ms for 100000 logs *  threads 4
 
     [java] Appender class org.apache.log4j.FileAppender
     [java] Took 27243ms for 100000 logs *  threads 4
 
     [java] Appender class org.apache.log4j.concurrent.FileAppender
     [java] Took 23172ms for 100000 logs *  threads 4

That's about 10%, though what is designed to be used for instead is SNMP
traps, database logging, etc.  As I said, most of the CPU is spent
formatting the message.

> Since the existing Layouts recycle the string buffer, in the single 
> threaded case, I would expect the existing code to outperform your version 
> which creates a new CharArrayWriter with each conversion. You seem to 
> indicate that the performances are more or less on par.

I think they're par, if not better.  A modern JVM is designed with lots
of temporary objects in mind.

Actually, reuse seems to be 10-15% worse.  Feel free to play around with
the test I attached.

For new StringBuffer() 231
For reuse StringBuffer() 211
For new StringBuffer() 175
For reuse StringBuffer() 209
For new StringBuffer() 191
For reuse StringBuffer() 205
For new StringBuffer() 176
For reuse StringBuffer() 201
For new StringBuffer() 173
For reuse StringBuffer() 219
For new StringBuffer() 174
For reuse StringBuffer() 194
For new StringBuffer() 174
For reuse StringBuffer() 204
For new StringBuffer() 176
For reuse StringBuffer() 204
For new StringBuffer() 179
For reuse StringBuffer() 201
For new StringBuffer() 173
For reuse StringBuffer() 205

import java.util.ArrayList;
import java.io.File;

public class TestLoop {

  static String x = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
  static String result;

  public static void main(String args[]) throws Exception {

    for (int times = 0 ; times < 10; times++) {

      Thread.sleep(500);

      long start = System.currentTimeMillis();
      for (int i = 0; i < 100000; i++) {
        result = new StringBuffer(100).append(x).toString();
      }
      long end = System.currentTimeMillis();

      Thread.sleep(500);

      StringBuffer sb = new StringBuffer(100);
      long start2 = System.currentTimeMillis();
      for (int i = 0; i < 100000; i++) {
        sb.setLength(0);
        sb.append(x);
        result = sb.toString();
      }
      long end2 = System.currentTimeMillis();

      System.out.println("For new StringBuffer() " + (end - start));
      System.out.println("For reuse StringBuffer() " + (end2 - start2));
    }
  }

}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to