]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/java/FieldAccessTest.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / performance / java / FieldAccessTest.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.tests.performance.java;
13
14 import org.simantics.db.testing.base.TestCommonPerf;
15
16 /**
17  *
18  */
19 public class FieldAccessTest extends TestCommonPerf {
20
21         final static class A {
22                 
23                 final private int value;
24                 
25                 public A(int value) {
26                         this.value = value;
27                 }
28                 
29                 public int getValue() {
30                         return value;
31                 }
32                 
33         }
34         
35         final static class B {
36                 
37                 final private int value;
38                 
39                 public B(int value) {
40                         this.value = value;
41                 }
42                 
43         }
44
45         public static int LEN1 = 10000;
46         public static int LEN2 = 1000000000;
47
48         public void test() throws Exception {
49
50                 
51                 A a = new A(1);
52                 B b = new B(1);
53
54                 int counter = 0;
55                 long start = System.nanoTime();
56                 for(int i=0;i<LEN1;i++) counter += a.getValue();  
57                 long duration = System.nanoTime() - start;
58
59                 int counter2 = 0;
60                 long start2 = System.nanoTime();
61                 for(int i=0;i<LEN1;i++) counter2 += b.value;  
62                 long duration2 = System.nanoTime() - start2;
63
64                 int counter3 = 0;
65                 long start3 = System.nanoTime();
66                 for(int i=0;i<LEN2;i++) counter3 += a.getValue();  
67                 long duration3 = System.nanoTime() - start3;
68
69                 int counter4 = 0;
70                 long start4 = System.nanoTime();
71                 for(int i=0;i<LEN2;i++) counter4 += b.value;  
72                 long duration4 = System.nanoTime() - start4;
73                 
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.");
78                 
79         }
80         
81 }