1

I implemented two algorithms in Java.

To compare their effectiveness, I call each function 1000 times and compare the execution time (using System.currentTimeMillis()).

It needs 2500 ms to execute the first one and 1300 ms for the second one.

With these results, I thought have a significative difference (in term of execution time) in JavaCard.

But if I load 2 applets on a JavaCard, which correspond to the functions described, the first one takes 2000 ms and the second one 1750 ms...

How explain that in Java, it looks almost 2 times faster, but not in JavaCard ? I paid attention that I don't write in EEPROM but in RAM so it can't be the source of the problem.

Do you have any argument to explain this phenomenon ? Thank you in advance.

Raoul722
  • 1,222
  • 13
  • 30
  • 3
    Mandatory comment "How do I write a correct micro-benchmark in Java?" http://stackoverflow.com/questions/504103/how-do-i-write-a-correct-micro-benchmark-in-java – reto May 26 '15 at 12:15
  • 3
    Java and JavaCard are two completely different technologies - they share only a subset of syntax, that is all. Just the word "JavaCard" can be a little misleading... I think you should not look for any connection between Java and JavaCard. – vojta May 26 '15 at 12:16
  • Show me the algorithm code please。 – JavaCardOS May 27 '15 at 09:11

2 Answers2

2

You run the algorithm is in two different platform, so the final machine language is not the same.

sunshine
  • 44
  • 1
0

Benchmark testing is not straightforward in Java. You can't just call a method in a loop and expect consistent and reliable results. You have to take into account many factors, compiler optimization and GC just to name a few. Pick up a performance testing tool for Java to do it properly.

vempo
  • 3,093
  • 1
  • 14
  • 16