01: // $Id: LogTest.java,v 1.3 2005/08/24 04:47:11 belaban Exp $
02:
03: package org.jgroups.tests;
04:
05: import junit.framework.TestCase;
06: import org.apache.commons.logging.Log;
07: import org.apache.commons.logging.LogFactory;
08:
09: /**
10: * Computes cost of logging
11: */
12: public class LogTest extends TestCase {
13: static final Log log = LogFactory.getLog(LogTest.class);
14: final boolean trace = log.isTraceEnabled();
15: final int NUM = 10000;
16: long start, stop, diff;
17:
18: public LogTest(String name) {
19: super (name);
20: }
21:
22: public void testSpeedWithSingleTraceStatement() {
23: start = System.currentTimeMillis();
24: for (int i = 0; i < NUM; i++) {
25: if (log.isTraceEnabled()) {
26: log.trace("this is log statement number " + i
27: + " from Bela");
28: }
29: }
30: stop = System.currentTimeMillis();
31: System.out.println("took " + (stop - start) + "ms for " + NUM
32: + " 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
40: + " from Bela");
41: }
42: }
43: stop = System.currentTimeMillis();
44: System.out.println("took " + (stop - start) + "ms for " + NUM
45: + " log statements");
46: }
47:
48: public void testSpeedWithTwoTraceStatements() {
49: start = System.currentTimeMillis();
50: for (int i = 0; i < NUM; i++) {
51: if (log.isTraceEnabled()) {
52: log.trace("this is log statement number " + i);
53: log.trace(" from Bela");
54: }
55: }
56: stop = System.currentTimeMillis();
57: System.out.println("took " + (stop - start) + "ms for " + NUM
58: + " log statements");
59: }
60:
61: public static void main(String[] args) {
62: String[] testCaseName = { LogTest.class.getName() };
63: junit.textui.TestRunner.main(testCaseName);
64: }
65:
66: }
|