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 FieldAccessTest extends TestCommonPerf {
21 final static class A {
23 final private int value;
29 public int getValue() {
35 final static class B {
37 final private int value;
45 public static int LEN1 = 10000;
46 public static int LEN2 = 1000000000;
48 public void test() throws Exception {
55 long start = System.nanoTime();
56 for(int i=0;i<LEN1;i++) counter += a.getValue();
57 long duration = System.nanoTime() - start;
60 long start2 = System.nanoTime();
61 for(int i=0;i<LEN1;i++) counter2 += b.value;
62 long duration2 = System.nanoTime() - start2;
65 long start3 = System.nanoTime();
66 for(int i=0;i<LEN2;i++) counter3 += a.getValue();
67 long duration3 = System.nanoTime() - start3;
70 long start4 = System.nanoTime();
71 for(int i=0;i<LEN2;i++) counter4 += b.value;
72 long duration4 = System.nanoTime() - start4;
74 System.out.println("Finished in " + 1e-9*duration + "s.");
75 System.out.println("Finished in " + 1e-9*duration2 + "s.");
76 System.out.println("Finished in " + 1e-9*duration3 + "s.");
77 System.out.println("Finished in " + 1e-9*duration4 + "s.");