View | Details | Raw Unified | Return to bug 48922
Collapse All | Expand All

(-)test/org/apache/catalina/connector/TestBenchmarkDate.java (+90 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 * 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 * 
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
package org.apache.catalina.connector;
19
20
import junit.framework.TestCase;
21
22
/**
23
 * Some testing performed at the OpenSource Jumpstart event at IBM
24
 */
25
public class TestBenchmarkDate extends TestCase {
26
	
27
	public void testBug48922() throws Exception {
28
        // Is it better to use a sync or a thread local here?
29
        BenchmarkTest benchmark = new BenchmarkTest();
30
        Runnable[] tests = new Runnable[] {
31
                new TestBenchmarkInitTime() };
32
        benchmark.doTest(5, tests);
33
    }
34
        
35
    private static class TestBenchmarkInitTime implements Runnable {
36
37
		@Override
38
		public void run() {
39
			// TODO Auto-generated method stub
40
			new Request();
41
		}    
42
    }
43
44
    private static class BenchmarkTest {
45
        public void doTest(int threadCount, Runnable[] tests) throws Exception {
46
            for (int iterations = 100000; iterations < 1000001; iterations += 100000) {
47
                for (int i = 0; i < tests.length; i++) {
48
                    doTestInternal(threadCount, iterations, tests[i]);
49
                }
50
            }
51
        }
52
53
        private void doTestInternal(int threadCount, int iterations,
54
                Runnable test) throws Exception {
55
            long start = System.currentTimeMillis();
56
            Thread[] threads = new Thread[threadCount];
57
            for (int i = 0; i < threadCount; i++) {
58
                threads[i] = new Thread(new TestThread(iterations, test));
59
            }
60
            for (int i = 0; i < threadCount; i++) {
61
                threads[i].start();
62
            }
63
            for (int i = 0; i < threadCount; i++) {
64
                threads[i].join();
65
            }
66
            long end = System.currentTimeMillis();
67
68
            System.out.println(test.getClass().getSimpleName() + ": "
69
                    + threadCount + " threads and " + iterations
70
                    + " iterations using " + test + " took " + (end - start)
71
                    + "ms");
72
        }
73
    }
74
    
75
    private static class TestThread implements Runnable {
76
        private int count;
77
        private Runnable test;
78
79
        public TestThread(int count, Runnable test) {
80
            this.count = count;
81
            this.test = test;
82
        }
83
84
        public void run() {
85
            for (int i = 0; i < count; i++) {
86
                test.run();
87
            }
88
        }
89
    }
90
}

Return to bug 48922