Path: blob/master/test/jdk/java/beans/Performance/TestIntrospector.java
41149 views
/*1* Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @summary Tests just a benchmark of introspector performance26* @author Mark Davidson27* @run main/manual TestIntrospector28*/2930import java.beans.BeanInfo;31import java.beans.IntrospectionException;32import java.beans.Introspector;3334/**35* This test is just a benchmark of introspector performance.36*/37public class TestIntrospector {38private static final Class[] TYPES = {39javax.swing.Box.class,40javax.swing.DefaultComboBoxModel.class,41javax.swing.DefaultCellEditor.class,42javax.swing.DefaultComboBoxModel.class,43javax.swing.DefaultListModel.class,44javax.swing.ImageIcon.class,45javax.swing.JApplet.class,46javax.swing.JButton.class,47javax.swing.JCheckBox.class,48javax.swing.JColorChooser.class,49javax.swing.JComboBox.class,50javax.swing.JDesktopPane.class,51javax.swing.JDialog.class,52javax.swing.JEditorPane.class,53javax.swing.JFileChooser.class,54javax.swing.JFrame.class,55javax.swing.JInternalFrame.class,56javax.swing.JLabel.class,57javax.swing.JList.class,58javax.swing.JMenu.class,59javax.swing.JMenuBar.class,60javax.swing.JMenuItem.class,61javax.swing.JOptionPane.class,62javax.swing.JPanel.class,63javax.swing.JPasswordField.class,64javax.swing.JPopupMenu.class,65javax.swing.JProgressBar.class,66javax.swing.JRadioButton.class,67javax.swing.JRadioButtonMenuItem.class,68javax.swing.JRootPane.class,69javax.swing.JScrollPane.class,70javax.swing.JSeparator.class,71javax.swing.JSlider.class,72javax.swing.JSplitPane.class,73javax.swing.JTabbedPane.class,74javax.swing.JTable.class,75javax.swing.JTextField.class,76javax.swing.JTextArea.class,77javax.swing.JTextPane.class,78javax.swing.JToggleButton.class,79javax.swing.JToolBar.class,80javax.swing.JToolTip.class,81javax.swing.JTree.class,82javax.swing.JWindow.class,83java.awt.Button.class,84java.awt.Canvas.class,85java.awt.Checkbox.class,86java.awt.Choice.class,87java.awt.Dialog.class,88java.awt.FileDialog.class,89java.awt.Frame.class,90java.awt.Image.class,91java.awt.List.class,92java.awt.Menu.class,93java.awt.MenuBar.class,94java.awt.MenuItem.class,95java.awt.Panel.class,96java.awt.Point.class,97java.awt.Rectangle.class,98java.awt.Scrollbar.class,99java.awt.TextArea.class,100java.awt.TextField.class,101java.awt.Window.class,102};103104public static void main(String[] args) throws IntrospectionException {105StringBuilder sb = null;106if (args.length > 0) {107if (args[0].equals("show")) {108sb = new StringBuilder(65536);109}110}111Introspector.flushCaches();112int count = (sb != null) ? 10 : 100;113long time = -System.currentTimeMillis();114for (int i = 0; i < count; i++) {115test(sb);116test(sb);117Introspector.flushCaches();118}119time += System.currentTimeMillis();120System.out.println("Time (average): " + time / count);121}122123private static void test(StringBuilder sb) throws IntrospectionException {124long time = 0L;125if (sb != null) {126sb.append("Time\t#Props\t#Events\t#Methods\tClass\n");127sb.append("----------------------------------------");128time = -System.currentTimeMillis();129}130for (Class type : TYPES) {131test(sb, type);132}133if (sb != null) {134time += System.currentTimeMillis();135sb.append("\nTime: ").append(time).append(" ms\n");136System.out.println(sb);137sb.setLength(0);138}139}140141private static void test(StringBuilder sb, Class type) throws IntrospectionException {142long time = 0L;143if (sb != null) {144time = -System.currentTimeMillis();145}146BeanInfo info = Introspector.getBeanInfo(type);147if (sb != null) {148time += System.currentTimeMillis();149sb.append('\n').append(time);150sb.append('\t').append(info.getPropertyDescriptors().length);151sb.append('\t').append(info.getEventSetDescriptors().length);152sb.append('\t').append(info.getMethodDescriptors().length);153sb.append('\t').append(type.getName());154}155}156}157158159