1 package org.apache.ojb.broker; 2 3 import junit.framework.TestCase; 4 5 import java.util.Map ; 6 import java.util.HashMap ; 7 8 import org.apache.ojb.broker.metadata.DescriptorRepository; 9 import org.apache.ojb.broker.metadata.MetadataManager; 10 11 19 public class IdentityPerformanceTest extends TestCase 20 { 21 PersistenceBroker broker; 22 private static Class CLASS = IdentityPerformanceTest.class; 23 private static final int ITERATIONS = 10000; 24 25 public static void main(String [] args) 26 { 27 String [] arr = {CLASS.getName()}; 28 junit.textui.TestRunner.main(arr); 29 } 30 31 public void testIdentityIterations() 32 { 33 Article art = new Article(); 34 art.setArticleName("OJB O/R mapping power"); 35 ProductGroup pg = new ProductGroup(); 36 pg.setName("Software"); 37 art.setProductGroup(pg); 38 Identity artOID = new Identity(art,broker); 40 long start = System.currentTimeMillis(); 41 for (int i = 0; i < ITERATIONS; i++) 42 { 43 artOID = new Identity(art,broker); 44 } 45 long stop = System.currentTimeMillis(); 46 System.out.println("total time to build " + ITERATIONS + " identities " + (stop - start) + " ms."); 47 System.out.println("time to build one Identity " + ((stop - start) / ITERATIONS) + " ms."); 48 } 49 public void testMapIterations() 50 { 51 long start = System.currentTimeMillis(); 52 Map temp; 53 54 for (int i = 0; i < ITERATIONS; i++) 55 { 56 temp = new HashMap (); 57 } 58 long stop = System.currentTimeMillis(); 59 System.out.println("total time to build " + ITERATIONS + " HashMaps " + (stop - start) + " ms."); 60 System.out.println("time to build one HashMaps " + ((stop - start) / ITERATIONS) + " ms."); 61 } 62 public void testDescriptorRepositoryGetDescriptorForIterations() 63 { 64 long start = System.currentTimeMillis(); 65 DescriptorRepository descriptorRepository = MetadataManager.getInstance().getRepository(); 66 for (int i = 0; i < ITERATIONS; i++) 67 { 68 descriptorRepository.getDescriptorFor(Article.class); 69 } 70 long stop = System.currentTimeMillis(); 71 System.out.println("total time to getDescriptorFor " + ITERATIONS + " times " + (stop - start) + " ms."); 72 System.out.println("time to call one getDescriptorFor " + ((stop - start) / ITERATIONS) + " ms."); 73 } 74 } 75 | Popular Tags |