]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.history/test/org/simantics/history/test/TestBindingPerformance.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.history / test / org / simantics / history / test / TestBindingPerformance.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.history.test;\r
13 \r
14 import org.simantics.databoard.Bindings;\r
15 import org.simantics.databoard.binding.Binding;\r
16 import org.simantics.history.util.ValueBand;\r
17 \r
18 /**\r
19  * Which is faster binding to use? \r
20  * \r
21  *    1. Write to record with reflection\r
22  *    \r
23  *    \r
24  *    \r
25  *    2. Write to object array with boxed primitives \r
26  *    \r
27  *    \r
28  *\r
29  */\r
30 public class TestBindingPerformance {\r
31         \r
32         public static class Sample {\r
33                 public double time, endTime, value, lastValue, min, max, avg, median;\r
34                 public byte quality;\r
35                 public int count;\r
36         }       \r
37         \r
38         public static void test( Binding b ) throws Exception {\r
39                 \r
40                 Object s = b.createDefault();\r
41                 ValueBand band = new ValueBand( b, s );\r
42                                 \r
43                 for (int i=0; i<10000000; i++) {\r
44                         double value = i;\r
45                         band.setTime(Bindings.DOUBLE, value);\r
46                         band.setEndTime(Bindings.DOUBLE, value);\r
47                         band.setValue(Bindings.DOUBLE, value);\r
48                         band.setLastValue(Bindings.DOUBLE, value);\r
49                         band.setMin(Bindings.DOUBLE, value);\r
50                         band.setMax(Bindings.DOUBLE, value);\r
51                         band.setAvg(Bindings.DOUBLE, value);\r
52                         band.setMedian(Bindings.DOUBLE, value);\r
53                 }\r
54                 \r
55         }\r
56         \r
57         public static void main(String[] args) throws Exception {\r
58                 \r
59                 Binding b1 = Bindings.getBinding( Sample.class );\r
60                 Binding b2 = Bindings.getBinding( b1.type() );\r
61                 \r
62                 test(b1);\r
63                 test(b2);\r
64                 \r
65                 long ct = System.currentTimeMillis();\r
66                 test(b1);\r
67                 System.out.println(System.currentTimeMillis()-ct);\r
68 \r
69                 ct = System.currentTimeMillis();\r
70                 test(b2);\r
71                 System.out.println(System.currentTimeMillis()-ct);\r
72                 \r
73         }\r
74 \r
75 }\r