]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.history/test/org/simantics/history/test/TestBindingPerformance.java b/bundles/org.simantics.history/test/org/simantics/history/test/TestBindingPerformance.java
new file mode 100644 (file)
index 0000000..b047b3f
--- /dev/null
@@ -0,0 +1,75 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.history.test;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.history.util.ValueBand;\r
+\r
+/**\r
+ * Which is faster binding to use? \r
+ * \r
+ *    1. Write to record with reflection\r
+ *    \r
+ *    \r
+ *    \r
+ *    2. Write to object array with boxed primitives \r
+ *    \r
+ *    \r
+ *\r
+ */\r
+public class TestBindingPerformance {\r
+       \r
+       public static class Sample {\r
+               public double time, endTime, value, lastValue, min, max, avg, median;\r
+               public byte quality;\r
+               public int count;\r
+       }       \r
+       \r
+       public static void test( Binding b ) throws Exception {\r
+               \r
+               Object s = b.createDefault();\r
+               ValueBand band = new ValueBand( b, s );\r
+                               \r
+               for (int i=0; i<10000000; i++) {\r
+                       double value = i;\r
+                       band.setTime(Bindings.DOUBLE, value);\r
+                       band.setEndTime(Bindings.DOUBLE, value);\r
+                       band.setValue(Bindings.DOUBLE, value);\r
+                       band.setLastValue(Bindings.DOUBLE, value);\r
+                       band.setMin(Bindings.DOUBLE, value);\r
+                       band.setMax(Bindings.DOUBLE, value);\r
+                       band.setAvg(Bindings.DOUBLE, value);\r
+                       band.setMedian(Bindings.DOUBLE, value);\r
+               }\r
+               \r
+       }\r
+       \r
+       public static void main(String[] args) throws Exception {\r
+               \r
+               Binding b1 = Bindings.getBinding( Sample.class );\r
+               Binding b2 = Bindings.getBinding( b1.type() );\r
+               \r
+               test(b1);\r
+               test(b2);\r
+               \r
+               long ct = System.currentTimeMillis();\r
+               test(b1);\r
+               System.out.println(System.currentTimeMillis()-ct);\r
+\r
+               ct = System.currentTimeMillis();\r
+               test(b2);\r
+               System.out.println(System.currentTimeMillis()-ct);\r
+               \r
+       }\r
+\r
+}\r