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