001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.openide.util;
043:
044: import org.openide.utildata.UtilClass;
045: import org.netbeans.performance.Benchmark;
046: import java.util.ResourceBundle;
047:
048: public class NbBundleTest extends Benchmark {
049:
050: public NbBundleTest(String name) {
051: super (name, new Integer[] { new Integer(1), new Integer(10),
052: new Integer(100), new Integer(1000) });
053: }
054:
055: private String[] keys;
056:
057: protected void setUp() {
058: int count = getIterationCount();
059: int param = ((Integer) getArgument()).intValue();
060: keys = new String[param];
061: for (int i = 0; i < param; i++) {
062: keys[i] = "MSG_BundleTest_" + i;
063: }
064: }
065:
066: protected void tearDown() {
067: keys = null;
068: }
069:
070: public void testGetMessageUsingClass() throws Exception {
071: int count = getIterationCount();
072: int magnitude = ((Integer) getArgument()).intValue();
073:
074: while (count-- > 0) {
075: // do the stuff here,
076: for (int number = 0; number < magnitude; number++) {
077: NbBundle.getMessage(UtilClass.class, keys[number]);
078: }
079: }
080: }
081:
082: public void testGetMessageUsingClassFullBrand() throws Exception {
083: int count = getIterationCount();
084: int magnitude = ((Integer) getArgument()).intValue();
085: NbBundle.setBranding("brand1");
086:
087: while (count-- > 0) {
088: // do the stuff here,
089: for (int number = 0; number < magnitude; number++) {
090: NbBundle.getMessage(UtilClass.class, keys[number]);
091: }
092: }
093: NbBundle.setBranding(null);
094: }
095:
096: public void testGetMessageUsingEmptyBrand() throws Exception {
097: int count = getIterationCount();
098: int magnitude = ((Integer) getArgument()).intValue();
099: NbBundle.setBranding("brand2");
100:
101: while (count-- > 0) {
102: // do the stuff here,
103: for (int number = 0; number < magnitude; number++) {
104: NbBundle.getMessage(UtilClass.class, keys[number]);
105: }
106: }
107:
108: NbBundle.setBranding(null);
109: }
110:
111: private ResourceBundle bundle;
112:
113: private synchronized ResourceBundle getBundle() {
114: if (bundle == null) {
115: bundle = NbBundle.getBundle(UtilClass.class);
116: }
117: return bundle;
118: }
119:
120: private synchronized void clearBundle() {
121: bundle = null;
122: }
123:
124: public void testGetMessageUsingLazyCache() throws Exception {
125: int count = getIterationCount();
126: int magnitude = ((Integer) getArgument()).intValue();
127:
128: while (count-- > 0) {
129: // do the stuff here,
130: for (int number = 0; number < magnitude; number++) {
131: getBundle().getString(keys[number]);
132: }
133: clearBundle();
134: }
135: }
136:
137: public void testGetMessageUsingCachedBundle() throws Exception {
138: int count = getIterationCount();
139: int magnitude = ((Integer) getArgument()).intValue();
140:
141: while (count-- > 0) {
142: ResourceBundle bundle = NbBundle.getBundle(UtilClass.class);
143: // do the stuff here,
144: for (int number = 0; number < magnitude; number++) {
145: bundle.getString(keys[number]);
146: }
147: }
148: }
149:
150: public void testGetMessageUsingCachedBundleFullBrand()
151: throws Exception {
152: int count = getIterationCount();
153: int magnitude = ((Integer) getArgument()).intValue();
154: NbBundle.setBranding("brand1");
155:
156: while (count-- > 0) {
157: ResourceBundle bundle = NbBundle.getBundle(UtilClass.class);
158: // do the stuff here,
159: for (int number = 0; number < magnitude; number++) {
160: bundle.getString(keys[number]);
161: }
162: }
163: NbBundle.setBranding(null);
164: }
165:
166: public void testGetMessageUsingCachedBundleEmptyBrand()
167: throws Exception {
168: int count = getIterationCount();
169: int magnitude = ((Integer) getArgument()).intValue();
170: NbBundle.setBranding("brand2");
171:
172: while (count-- > 0) {
173: ResourceBundle bundle = NbBundle.getBundle(UtilClass.class);
174: // do the stuff here,
175: for (int number = 0; number < magnitude; number++) {
176: bundle.getString(keys[number]);
177: }
178: }
179: NbBundle.setBranding(null);
180: }
181:
182: public static void main(String[] args) {
183: simpleRun(NbBundleTest.class);
184: }
185: }
|