javamillisecondsnanotime

Is System.nanoTime(); or System.currentTimeMillis(); better for a game


In a game loop everyone uses System.nanoTime() but for something like animations, the speed of something, etc some people use System.currentTimeMillis() and some use System.nanoTime(). Which one should I be using?


Solution

  • You should be using whichever is appropriate to your needs.

    The two examples you gave are fundamentally different:

    Nobody is likely to actually1 tell the difference between using millisecond or nanosecond clocks in games and other applications where the primary goal is smooth human-computer interaction.

    In short: there is no "right" way.


    1 - They may think that they can tell, but it wouldn't stand up to rigorous scientific testing.