1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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.db.tests.performance.java;
14 import org.simantics.db.testing.base.TestCommonPerf;
19 public class CastTest extends TestCommonPerf {
23 public int getValue();
27 final static class B implements A {
29 final private int value;
36 public int getValue() {
42 final static class C implements A {
44 final private int value;
51 public int getValue() {
57 public static int LEN1 = 10000;
58 public static int LEN2 = 1000000000;
60 public void test() throws Exception {
66 long start = System.nanoTime();
67 for(int i=0;i<LEN1;i++) counter += a.getValue();
68 long duration = System.nanoTime() - start;
71 long start2 = System.nanoTime();
72 for(int i=0;i<LEN1;i++) counter2 += ((B)a).value;
73 long duration2 = System.nanoTime() - start2;
76 long start3 = System.nanoTime();
77 for(int i=0;i<LEN2;i++) counter3 += b.value;
78 long duration3 = System.nanoTime() - start3;
81 long start4 = System.nanoTime();
82 for(int i=0;i<LEN2;i++) counter4 += compB(a);
83 long duration4 = System.nanoTime() - start4;
85 System.out.println("Finished in " + 1e-9*duration + "s.");
86 System.out.println("Finished in " + 1e-9*duration2 + "s.");
87 System.out.println("Finished in " + 1e-9*duration3 + "s.");
88 System.out.println("Finished in " + 1e-9*duration4 + "s.");
92 private int compA(A a) {
93 int ret = a.getValue();
97 private int compB(A a) {
99 // if(a instanceof B) return ((B)a).value;
100 // else if (a instanceof C) return ((C)a).value;