Path: blob/master/test/jdk/java/beans/Performance/TestPropertyChangeSupport.java
41149 views
/*1* Copyright (c) 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* @run main/manual TestPropertyChangeSupport26* @summary Tests just a benchmark of PropertyChangeSupport performance27* @author Sergey Malenkov28*/2930import java.beans.PropertyChangeEvent;31import java.beans.PropertyChangeListener;32import java.beans.PropertyChangeSupport;3334public class TestPropertyChangeSupport implements PropertyChangeListener {35private static final String NAME = "property";3637public static void main(String[] args) {38for (int i = 1; i <= 3; i++) {39test(i, 1, 10000000);40test(i, 10, 1000000);41test(i, 100, 100000);42test(i, 1000, 10000);43test(i, 10000, 1000);44test(i, 20000, 1000);45}46}4748private static void test(int step, int listeners, int attempts) {49TestPropertyChangeSupport test = new TestPropertyChangeSupport();50PropertyChangeSupport pcs = new PropertyChangeSupport(test);51PropertyChangeEvent eventNull = new PropertyChangeEvent(test, null, null, null);52PropertyChangeEvent eventName = new PropertyChangeEvent(test, NAME, null, null);53long time1 = System.currentTimeMillis();54for (int i = 0; i < listeners; i++) {55pcs.addPropertyChangeListener(test);56pcs.addPropertyChangeListener(NAME, test);57}58long time2 = System.currentTimeMillis();59for (int i = 0; i < attempts; i++) {60pcs.firePropertyChange(eventNull);61pcs.firePropertyChange(eventName);62}63long time3 = System.currentTimeMillis();64time1 = time2 - time1; // time of adding the listeners65time2 = time3 - time2; // time of firing the events66System.out.println("Step: " + step67+ "; Listeners: " + listeners68+ "; Attempts: " + attempts69+ "; Time (ms): " + time1 + "/" + time2);70}7172public void propertyChange(PropertyChangeEvent event) {73}74}757677