1 7 package com.inversoft.beans.test; 8 9 10 import java.beans.IntrospectionException ; 11 import java.beans.PropertyDescriptor ; 12 import java.lang.reflect.Method ; 13 14 import junit.framework.TestCase; 15 16 import com.inversoft.beans.BeanException; 17 import com.inversoft.beans.BeanProperty; 18 19 20 25 public class SpeedPerformanceTest extends TestCase { 26 27 28 public static final int ITERATIONS = 10000; 29 30 public SpeedPerformanceTest(String name) { 31 super(name); 32 } 33 34 public void testBeanPropertyConstructorSpeed() { 35 36 try { 37 long timeBefore = System.currentTimeMillis(); 38 39 for (int i = 0; i < ITERATIONS; i++) { 40 new BeanProperty("integer1", Bean1.class); 41 } 42 43 long timeAfter = System.currentTimeMillis(); 44 System.err.println("The number of millis for jBeans BeanProperty construction: " 45 + (timeAfter - timeBefore)); 46 } catch (BeanException be) { 47 fail(be.toString()); 48 } 49 50 try { 51 long timeBefore = System.currentTimeMillis(); 52 53 for (int i = 0; i < ITERATIONS; i++) { 54 new PropertyDescriptor ("integer1", Bean1.class); 55 } 56 57 long timeAfter = System.currentTimeMillis(); 58 System.err.println("The number of millis for java.beans PropertyDescriptor construcion: " 59 + (timeAfter - timeBefore)); 60 } catch (IntrospectionException ie) { 61 fail(ie.toString()); 62 } 63 } 64 65 public void testBeanPropertyReadSpeed() { 66 67 try { 68 Bean1 bean = new Bean1(); 69 BeanProperty prop = new BeanProperty("integer1", Bean1.class); 70 long timeBefore = System.currentTimeMillis(); 71 72 for (int i = 0; i < ITERATIONS; i++) { 73 prop.getPropertyValue(bean); 74 } 75 76 long timeAfter = System.currentTimeMillis(); 77 System.err.println("The number of millis for jBeans BeanProperty read: " 78 + (timeAfter - timeBefore)); 79 } catch (BeanException be) { 80 fail(be.toString()); 81 } 82 83 try { 84 Bean1 bean = new Bean1(); 85 PropertyDescriptor prop = new PropertyDescriptor ("integer1", Bean1.class); 86 Method method; 87 long timeBefore = System.currentTimeMillis(); 88 89 for (int i = 0; i < ITERATIONS; i++) { 90 try { 91 method = prop.getReadMethod(); 92 method.invoke(bean, null); 93 } catch (Exception e) { 94 fail(e.toString()); 95 } 96 } 97 98 long timeAfter = System.currentTimeMillis(); 99 System.err.println("The number of millis for java.beans PropertyDescriptor read: " 100 + (timeAfter - timeBefore)); 101 } catch (IntrospectionException ie) { 102 fail(ie.toString()); 103 } 104 } 105 106 public void testBeanPropertyWriteSpeed() { 107 108 try { 109 Bean1 bean = new Bean1(); 110 BeanProperty prop = new BeanProperty("integer1", Bean1.class); 111 long timeBefore = System.currentTimeMillis(); 112 113 for (int i = 0; i < ITERATIONS; i++) { 114 prop.setPropertyValue(bean, new Integer (42)); 115 } 116 117 long timeAfter = System.currentTimeMillis(); 118 System.err.println("The number of millis for jBeans BeanProperty write: " 119 + (timeAfter - timeBefore)); 120 } catch (BeanException be) { 121 fail(be.toString()); 122 } 123 124 try { 125 Bean1 bean = new Bean1(); 126 PropertyDescriptor prop = new PropertyDescriptor ("integer1", Bean1.class); 127 Method method; 128 long timeBefore = System.currentTimeMillis(); 129 130 for (int i = 0; i < ITERATIONS; i++) { 131 try { 132 method = prop.getWriteMethod(); 133 method.invoke(bean, new Object []{new Integer (42)}); 134 } catch (Exception e) { 135 fail(e.toString()); 136 } 137 } 138 139 long timeAfter = System.currentTimeMillis(); 140 System.err.println("The number of millis for java.beans PropertyDescriptor write: " 141 + (timeAfter - timeBefore)); 142 } catch (IntrospectionException ie) { 143 fail(ie.toString()); 144 } 145 } 146 } 147
| Popular Tags
|