wtorek, 22 stycznia 2013

Java and RPi - continued


After I had installed both jdk (open and oracle's), I started wondering what is the difference between them, when it comes to performance. Recently I found some time in the evening and wrote simple tests, which are not very accurate, but give the general notion about performance.

Let's take a look into tests:
ArrayListAppendTest
List<Long> list = new ArrayList<Long>();
for (long l = 0; l <1000000; l++) {
   list.add(l);
}

ArrayListInsertMiddleTest
List<Long> list = new ArrayList<Long>();
for (long l = 0; l < 1000; l++) {
   list.add(l);
}
for (long l = 0; l < 10000; l++) {
   list.add(500, l);
} 

ArrayListSortTest
List list = new ArrayList();
for (int i = 100000; i > 0; i--) {
   String str = String.format("String nr %5s", i);
   list.add(str);
}
Collections.sort(list);

LinkedListAppendTest, LinkedListInsertMiddleTest, LinkedListSortTest are exactly the same as for ArrayList, but with subtle change...

DoubleAddTest
double val = 0.0;
for (int i = 0; i< 1000000; i++) {
   val += (double) i;
}

SinusTest
for(int i = 0; i < 1000000; i++) {
   double val = Math.sin((double) i);
}

StringAppendTest
String [] strings = new String[1000];
for (int i = 0; i < strings.length; i++) {
   strings[i] = String.format("Str %d", i);
}
String concat = "";
for (int i = 0; i < strings.length; i++) {
   concat += strings[i];
}

All tests *ISTest use various input streams, *OSTest - output streams.

When it comes to reflection tests, I tried to instantiate class using classe's newInstance method, in case of CallMethod test I'm calling one argument method using reflection. Simple...

For comparison I executed test on my ancient computer (Amd64 3500+). After that I compiled and run tests on Raspberry Pi using proper JDK.

And the resulst are... interesting (execution time is in ms):

Test nameJDK Oracle 1.7 @ AMD64 3500Oracle JDK 1.8 ea @ RPiOpen JDK 1.7 @ RPiRatio
ArrayListAppendTest 348,6 2632 10965,1 4,2
ArrayListInsertMiddleTest 72,6 285,7 1024,7 3,6
ArrayListSortTest 19,6 292,9 2394,4 8,2
BufferedFileOS 12,2 45,4 856,4 18,9
DoubleAddTest 0,2 35,8 390,5 10,9
FileISTest 25,3 183,8 231,5 1,3
FileOSTest 96,8 524,9 1618,9 3,1
LinkedListAppendTest 636,1 3393,7 16634,3 4,9
LinkedListInsertMiddleTest 23,3 99,5 2159 21,7
LinkedListSortTest 44,8 270,9 2225,9 8,2
ReflectionCallMethodTest 116,3 803,2 3496,7 4,4
ReflectionNewInstanceTest 55,5 202,5 542,4 2,7
SinusTest 268,6 562,5 3722 6,6
StringAppendTest 49,3 254,4 489,1 1,9

As you can see Open JDK in those test is far behind oracle's (in column Ratio you can see, how much slower Open JDK was :/).
I think I stick to JDK 1.8 ea...

Brak komentarzy:

Prześlij komentarz