Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/Performance/TestVetoableChangeSupport.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 TestVetoableChangeSupport
27
* @summary Tests just a benchmark of VetoableChangeSupport performance
28
* @author Sergey Malenkov
29
*/
30
31
import java.beans.PropertyChangeEvent;
32
import java.beans.PropertyVetoException;
33
import java.beans.VetoableChangeListener;
34
import java.beans.VetoableChangeSupport;
35
36
public class TestVetoableChangeSupport implements VetoableChangeListener {
37
private static final String NAME = "property";
38
39
public static void main(String[] args) throws PropertyVetoException {
40
for (int i = 1; i <= 3; i++) {
41
test(i, 1, 10000000);
42
test(i, 10, 1000000);
43
test(i, 100, 100000);
44
test(i, 1000, 10000);
45
test(i, 10000, 1000);
46
test(i, 20000, 1000);
47
}
48
}
49
50
private static void test(int step, int listeners, int attempts) throws PropertyVetoException {
51
TestVetoableChangeSupport test = new TestVetoableChangeSupport();
52
VetoableChangeSupport vcs = new VetoableChangeSupport(test);
53
PropertyChangeEvent eventNull = new PropertyChangeEvent(test, null, null, null);
54
PropertyChangeEvent eventName = new PropertyChangeEvent(test, NAME, null, null);
55
long time1 = System.currentTimeMillis();
56
for (int i = 0; i < listeners; i++) {
57
vcs.addVetoableChangeListener(test);
58
vcs.addVetoableChangeListener(NAME, test);
59
}
60
long time2 = System.currentTimeMillis();
61
for (int i = 0; i < attempts; i++) {
62
vcs.fireVetoableChange(eventNull);
63
vcs.fireVetoableChange(eventName);
64
}
65
long time3 = System.currentTimeMillis();
66
time1 = time2 - time1; // time of adding the listeners
67
time2 = time3 - time2; // time of firing the events
68
System.out.println("Step: " + step
69
+ "; Listeners: " + listeners
70
+ "; Attempts: " + attempts
71
+ "; Time (ms): " + time1 + "/" + time2);
72
}
73
74
public void vetoableChange(PropertyChangeEvent event) {
75
}
76
}
77
78