Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/Performance/TestPropertyChangeSupport.java
41149 views
1
/*
2
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @run main/manual TestPropertyChangeSupport
27
* @summary Tests just a benchmark of PropertyChangeSupport performance
28
* @author Sergey Malenkov
29
*/
30
31
import java.beans.PropertyChangeEvent;
32
import java.beans.PropertyChangeListener;
33
import java.beans.PropertyChangeSupport;
34
35
public class TestPropertyChangeSupport implements PropertyChangeListener {
36
private static final String NAME = "property";
37
38
public static void main(String[] args) {
39
for (int i = 1; i <= 3; i++) {
40
test(i, 1, 10000000);
41
test(i, 10, 1000000);
42
test(i, 100, 100000);
43
test(i, 1000, 10000);
44
test(i, 10000, 1000);
45
test(i, 20000, 1000);
46
}
47
}
48
49
private static void test(int step, int listeners, int attempts) {
50
TestPropertyChangeSupport test = new TestPropertyChangeSupport();
51
PropertyChangeSupport pcs = new PropertyChangeSupport(test);
52
PropertyChangeEvent eventNull = new PropertyChangeEvent(test, null, null, null);
53
PropertyChangeEvent eventName = new PropertyChangeEvent(test, NAME, null, null);
54
long time1 = System.currentTimeMillis();
55
for (int i = 0; i < listeners; i++) {
56
pcs.addPropertyChangeListener(test);
57
pcs.addPropertyChangeListener(NAME, test);
58
}
59
long time2 = System.currentTimeMillis();
60
for (int i = 0; i < attempts; i++) {
61
pcs.firePropertyChange(eventNull);
62
pcs.firePropertyChange(eventName);
63
}
64
long time3 = System.currentTimeMillis();
65
time1 = time2 - time1; // time of adding the listeners
66
time2 = time3 - time2; // time of firing the events
67
System.out.println("Step: " + step
68
+ "; Listeners: " + listeners
69
+ "; Attempts: " + attempts
70
+ "; Time (ms): " + time1 + "/" + time2);
71
}
72
73
public void propertyChange(PropertyChangeEvent event) {
74
}
75
}
76
77