KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > StringBufferPerformance15Test


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tctest;
5
6 import com.tc.object.BaseDSOTestCase;
7
8 /*
9  * Unit test for measuring the overhead of StringBuffer for jdk1.5.
10  */

11 public class StringBufferPerformance15Test extends BaseDSOTestCase {
12   private final static int COUNT = 100000;
13
14   public void test() {
15     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
16     char[] appendString = new char[]{'t', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 't', 'e', 's', 't'};
17     long startTime = System.currentTimeMillis();
18     for (int i=0; i<COUNT; i++) {
19       sb.append(appendString);
20     }
21     long endTime = System.currentTimeMillis();
22     System.out.println("Time elapsed for non-shared StringBuffer: " + (endTime - startTime) + " ms.");
23   }
24  
25 }
26
Popular Tags