1 package org.simantics.databoard.tests;
5 * @author Toni Kalajainen <toni.kalajainen@iki.fi>
7 public class TestByteVsInt {
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);
13 public static int sum(int a, int b, int c, int d, int e, int f) {
17 public static long sum(long a, long b, long c, long d, long e, long f) {
21 public static void byteTest() {
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);
34 long y = System.nanoTime();
35 System.out.println("byte: "+(y-x)/*+" (sum="+(a+b+c+d+e+f)+")"*/);
39 public static void intTest() {
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);
52 long y = System.nanoTime();
53 System.out.println("int : "+(y-x)/*+" (sum="+(a+b+c+d+e+f)+")"*/);
57 public static void longTest() {
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);
70 long y = System.nanoTime();
71 System.out.println("long: "+(y-x)/*+" (sum="+(a+b+c+d+e+f)+")"*/);
77 public static void main(String[] args) {