1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.history.test;
\r
14 import org.simantics.databoard.Bindings;
\r
15 import org.simantics.databoard.binding.Binding;
\r
16 import org.simantics.history.util.ValueBand;
\r
19 * Which is faster binding to use?
\r
21 * 1. Write to record with reflection
\r
25 * 2. Write to object array with boxed primitives
\r
30 public class TestBindingPerformance {
\r
32 public static class Sample {
\r
33 public double time, endTime, value, lastValue, min, max, avg, median;
\r
34 public byte quality;
\r
38 public static void test( Binding b ) throws Exception {
\r
40 Object s = b.createDefault();
\r
41 ValueBand band = new ValueBand( b, s );
\r
43 for (int i=0; i<10000000; 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
57 public static void main(String[] args) throws Exception {
\r
59 Binding b1 = Bindings.getBinding( Sample.class );
\r
60 Binding b2 = Bindings.getBinding( b1.type() );
\r
65 long ct = System.currentTimeMillis();
\r
67 System.out.println(System.currentTimeMillis()-ct);
\r
69 ct = System.currentTimeMillis();
\r
71 System.out.println(System.currentTimeMillis()-ct);
\r