]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/scratch/org/simantics/databoard/tests/TestByteVsInt.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / scratch / org / simantics / databoard / tests / TestByteVsInt.java
1 package org.simantics.databoard.tests;
2
3 /**
4  *
5  * @author Toni Kalajainen <toni.kalajainen@iki.fi>
6  */
7 public class TestByteVsInt {
8
9         public static byte sum(byte a, byte b, byte c, byte d, byte e, byte f) {
10                 return (byte) (a+b+c+d+e+f);
11         }
12         
13         public static int sum(int a, int b, int c, int d, int e, int f) {
14                 return a+b+c+d+e+f;
15         }
16         
17         public static long sum(long a, long b, long c, long d, long e, long f) {
18                 return a+b+c+d+e+f;
19         }
20         
21         public static void byteTest() {
22                 System.gc();
23                 {
24                         long x = System.nanoTime();
25                         byte a = 6, b=3, c=67, d=2, e=-53, f=1;
26                         for (int i=0; i<1000000; i++) {
27                                 a = sum(a, b, c, d, e, f);
28                                 b = sum(b, c, d, e, f, a);
29                                 c = sum(c, d, e, f, a, b);
30                                 d = sum(d, e, f, a, b, c);
31                                 e = sum(e, f, a, b, c, d);
32                                 f = sum(f, a, b, c, d, e);                              
33                         }
34                         long y = System.nanoTime();
35                         System.out.println("byte: "+(y-x)/*+" (sum="+(a+b+c+d+e+f)+")"*/);
36                 }
37         }
38         
39         public static void intTest() {
40                 System.gc();
41                 {
42                         long x = System.nanoTime();
43                         int a = 6, b=3, c=67, d=2, e=-53, f=1;
44                         for (int i=0; i<1000000; i++) {
45                                 a = sum(a, b, c, d, e, f);
46                                 b = sum(b, c, d, e, f, a);
47                                 c = sum(c, d, e, f, a, b);
48                                 d = sum(d, e, f, a, b, c);
49                                 e = sum(e, f, a, b, c, d);
50                                 f = sum(f, a, b, c, d, e);                              
51                         }
52                         long y = System.nanoTime();
53                         System.out.println("int : "+(y-x)/*+" (sum="+(a+b+c+d+e+f)+")"*/);
54                 }                               
55         }
56         
57         public static void longTest() {
58                 System.gc();
59                 {
60                         long x = System.nanoTime();
61                         long a = 6, b=3, c=67, d=2, e=-53, f=1;
62                         for (int i=0; i<1000000; i++) {
63                                 a = sum(a, b, c, d, e, f);
64                                 b = sum(b, c, d, e, f, a);
65                                 c = sum(c, d, e, f, a, b);
66                                 d = sum(d, e, f, a, b, c);
67                                 e = sum(e, f, a, b, c, d);
68                                 f = sum(f, a, b, c, d, e);                              
69                         }
70                         long y = System.nanoTime();
71                         System.out.println("long: "+(y-x)/*+" (sum="+(a+b+c+d+e+f)+")"*/);
72                 }
73         }
74         
75         
76         
77         public static void main(String[] args) {
78                 
79                 byteTest();
80                 intTest();
81                 longTest();
82                 
83                 byteTest();
84                 intTest();
85                 longTest();
86
87                 byteTest();
88                 intTest();
89                 longTest();
90                 
91                 byteTest();
92                 intTest();
93                 longTest();
94
95                 byteTest();
96                 intTest();
97                 longTest();
98
99                 byteTest();
100                 intTest();
101                 longTest();
102                 
103         }
104         
105 }