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