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