KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > tests > LogTest


1 // $Id: LogTest.java,v 1.3 2005/08/24 04:47:11 belaban Exp $
2

3 package org.jgroups.tests;
4
5 import junit.framework.TestCase;
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8
9
10 /**
11  * Computes cost of logging
12  */

13 public class LogTest extends TestCase {
14     static final Log log=LogFactory.getLog(LogTest.class);
15     final boolean trace=log.isTraceEnabled();
16     final int NUM=10000;
17     long start, stop, diff;
18
19     public LogTest(String JavaDoc name) {
20         super(name);
21     }
22
23
24     public void testSpeedWithSingleTraceStatement() {
25         start=System.currentTimeMillis();
26         for(int i=0; i < NUM; i++) {
27             if(log.isTraceEnabled()) {
28                 log.trace("this is log statement number " + i + " from Bela");
29             }
30         }
31         stop=System.currentTimeMillis();
32         System.out.println("took " + (stop-start) + "ms for " + NUM + " log statements");
33     }
34
35     public void testSpeedWithSingleTraceStatementLogIsTracePreset() {
36         start=System.currentTimeMillis();
37         for(int i=0; i < NUM; i++) {
38             if(trace) {
39                 log.trace("this is log statement number " + i + " from Bela");
40             }
41         }
42         stop=System.currentTimeMillis();
43         System.out.println("took " + (stop-start) + "ms for " + NUM + " log statements");
44     }
45
46     public void testSpeedWithTwoTraceStatements() {
47         start=System.currentTimeMillis();
48         for(int i=0; i < NUM; i++) {
49             if(log.isTraceEnabled()) {
50                 log.trace("this is log statement number " + i);
51                 log.trace(" from Bela");
52             }
53         }
54         stop=System.currentTimeMillis();
55         System.out.println("took " + (stop-start) + "ms for " + NUM + " log statements");
56     }
57
58
59     public static void main(String JavaDoc[] args) {
60         String JavaDoc[] testCaseName={LogTest.class.getName()};
61         junit.textui.TestRunner.main(testCaseName);
62     }
63
64 }
65
Popular Tags