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