KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > IdentityPerformanceTest


1 package org.apache.ojb.broker;
2
3 import junit.framework.TestCase;
4
5 import java.util.Map JavaDoc;
6 import java.util.HashMap JavaDoc;
7
8 import org.apache.ojb.broker.metadata.DescriptorRepository;
9 import org.apache.ojb.broker.metadata.MetadataManager;
10
11 /**
12  * @author Matthew.Baird
13  *
14  * To change this generated comment edit the template variable "typecomment":
15  * Window>Preferences>Java>Templates.
16  * To enable and disable the creation of type comments go to
17  * Window>Preferences>Java>Code Generation.
18  */

19 public class IdentityPerformanceTest extends TestCase
20 {
21     PersistenceBroker broker;
22     private static Class JavaDoc CLASS = IdentityPerformanceTest.class;
23     private static final int ITERATIONS = 10000;
24
25     public static void main(String JavaDoc[] args)
26     {
27         String JavaDoc[] 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         // prime the pump.
39
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 JavaDoc temp;
53
54         for (int i = 0; i < ITERATIONS; i++)
55         {
56             temp = new HashMap JavaDoc();
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