Thanks for sharing ...
The highlighted comment was created in this revision.
Hi mate. Nice one, i was just starting to write my own and now you share yours :). I will take it right away.
You are welcome:) Feel free to ask any questions or report any problems, if they will appear:) But do not forget to share any improvements:)
Well :). I'm running (as usual) in very strange issues with System.nanoTime(). Maybe you can help me out with that. Looking at the sample table below your code, the max values look a little bit strange to me. I'm sure you are not spending 33ms on something. Using your class myself i run in the same issue. Therefore i spend some time to dig it out. To me it looks like the System.nanoTime() is not very reliable because it sometimes give simple wrong time differences back. Some quick googling on this issue shows that there are some different opinions on that :(. This might be have to do with the multi core structure on my mac and the time is grabbed from different cores ... who knows.
On the other hand, if this is true, than it could be that some issues with the skipped turns are also coming from this time glitch.
Of course, i can totally be wrong and missing some point here. Thats why i ask for a second thought :)
Take Care
Just quick replay before going to bed: you,at least, miss garbage collector. Im not sure, but i think, that its stop all other threads.
Good point. I didn't know that the garbage collection is messing with the time measurement. I guess this makes max/total value a little obsolete. Anyway i'm very happy that you shared the code and it showed me that i'm running on 2ms turns, and i learned something too :). And of course if i find something to improve the functionality i will share it with pleasure.
Have a good night.
Ok, now full reply:)
At first, GC MAY blocks all threads, and for me (Win7, Java 6, default settings) it DOES it, because, for example in battles between Tomcat and Scarlet in late rounds game periodically freezes for seconds...
For robocode milliseconds is completly useless, but my experience shows, that nanoseconds is fairly usefull and i did find out with them some ways to decrease skipped turns amount.
Maybe there is a sense to add some kind of protection against invalid values, for example, discard values larger that 10 ms or larger than mean value more than 10 times
Just for clarification if i write ms it means μs :). I guess i'm simple to lazy to look for the μ on my keyboard especially if the metric is narrowed to the micro decadic. Because millisecond is indeed quite useless for robocode :). But it shows that i should be more precise in future discussions. The correct prefix, if you have no μ, would be "2us" which looks mighty strange to me.