001: /*
002: * Copyright 2006 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core;
017:
018: import junit.framework.TestCase;
019:
020: import org.apache.commons.beanutils.PropertyUtilsBean;
021: import org.kuali.core.web.struts.pojo.PojoPropertyUtilsBean;
022:
023: public class PropertyUtilsBeanPerformanceTest extends TestCase {
024:
025: public static final int RUNS = 1;
026: public static final int COUNT = 100;
027:
028: public class Timer {
029: long t0;
030: long t1;
031:
032: Timer() {
033: t0 = System.currentTimeMillis();
034: }
035:
036: long getElapsed() {
037: t1 = System.currentTimeMillis();
038: return t1 - t0;
039: }
040: }
041:
042: public class Test1 {
043: String value;
044:
045: public String getValue() {
046: return value;
047: }
048:
049: public void setValue(String value) {
050: this .value = value;
051: }
052:
053: }
054:
055: public class Test2 {
056: Test1 test1;
057:
058: public Test1 getTest1() {
059: return test1;
060: }
061:
062: }
063:
064: public class Test3 {
065: Test2 test2;
066:
067: public Test2 getTest2() {
068: return test2;
069: }
070:
071: }
072:
073: public class Test4 {
074: Test3 test3;
075:
076: public Test3 getTest3() {
077: return test3;
078: }
079:
080: public void setTest3(Test3 test3) {
081: this .test3 = test3;
082: }
083:
084: }
085:
086: public void testPerformance() throws Exception {
087: Timer timer;
088: long elapsed;
089:
090: PropertyUtilsBean b = new PropertyUtilsBean();
091: PojoPropertyUtilsBean f = new PojoPropertyUtilsBean();
092:
093: Test4 t = new Test4();
094: t.test3 = new Test3();
095: t.test3.test2 = new Test2();
096: t.test3.test2.test1 = new Test1();
097: t.test3.test2.test1.value = "test";
098:
099: for (int j = 0; j < RUNS; j++) {
100:
101: timer = new Timer();
102: for (int i = 0; i < COUNT; i++) {
103: assertEquals(t.test3.test2.test1.value, "test");
104: }
105: elapsed = timer.getElapsed();
106: System.out.println("native: " + elapsed);
107:
108: timer = new Timer();
109: for (int i = 0; i < COUNT; i++) {
110: assertEquals(t.test3.test2.test1.value,
111: b.getNestedProperty(t,
112: "test3.test2.test1.value"));
113: }
114: elapsed = timer.getElapsed();
115: System.out.println("standard: " + elapsed);
116:
117: timer = new Timer();
118: for (int i = 0; i < COUNT; i++) {
119: assertEquals(t.test3.test2.test1.value,
120: f.getNestedProperty(t,
121: "test3.test2.test1.value"));
122: }
123: elapsed = timer.getElapsed();
124: System.out.println("custom: " + elapsed);
125:
126: }
127:
128: }
129:
130: }
|