This site requires JavaScript, please enable it in your browser!
Greenfoot back
Gevater_Tod4711
Gevater_Tod4711 wrote ...

2012/10/26

strange runtime values

Gevater_Tod4711 Gevater_Tod4711

2012/10/26

#
Hi all, I'm programming a graph drawing simulation and now I want to improve the running time. To improve the running time I first printed the time needed to calculate the values on the console and there I saw that most time no time is needed but sometimes time is needed to calculate the values or change things in the input string... The thing I don't realy understand is that the time needed is always 15 or 16 and this times come from some very different method calls. (like I sad sometimes calculating values, sometimes changing a string, sometimes rounding numbers...) This methodcalls which need this 15 or 16 milliseconds seem to occur randomly so my question: Why do the methods sometimes need not one ms and sometimes 15 or 16 ms? It is not realy a problem but I would be interested in where this times come from or why it are always 15 or 16 milliseconds. Would be great if anyone could explain this to me.
Upupzealot Upupzealot

2012/10/27

#
That's the limit of the method "System.currentTimeMillis()", on some OS, you could only get millis in multiples of 16.
mjrb4 mjrb4

2012/10/28

#
You may want to look at System.nanoTime() - I believe this solves the issues on some systems with granularity (multiples of 16 and so on.) However, benchmarking like this isn't going to get you very far unless there's a hugely noticeable lag in one of your methods. All sorts of things could happen (certain pieces of code could get cherry picked for optimisation by the JIT, GC could kick in giving an apparently long pause, another process running on the system could slow things down...) that would cause a few ms slow-down here and there. You could use a proper profiling tool (such as that found in Netbeans) if you really want to work out what's taking up the most time and where, but this is obviously a more complicated approach (Greenfoot has no built in profiler.)
Upupzealot Upupzealot

2012/10/28

#
yes, System.nanoTime() is much better than System.currentTimeMillis(), it could correct to about 5 millisecond.
Gevater_Tod4711 Gevater_Tod4711

2012/10/28

#
Well I just was searching for a method which takes much time and maybe itn't necessary. I don't need a real "hardcore optimisation". I was just wondering about this strange values. But thank you for the replies.
You need to login to post a reply.