[2.0.72] profiler within on_tick giving inconsistent results based on game.speed

Bugs that are actually features.
BurninSun
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Fri Mar 16, 2018 4:54 am
Contact:

[2.0.72] profiler within on_tick giving inconsistent results based on game.speed

Post by BurninSun »

I'm getting inconsistent results from the in game profiler depending on the game.speed setting when using the profiler within an on_tick event. Running with game.speed = 1 is resulting in profile times 2x higher than when using game.speed = 1000. The profiler is .restart() and .stop() within the on_tick event function and so should not be affected by game speed at all.

Start a new game and run the following code:

Code: Select all

game.speed = 1
local start_tick = game.tick
local profiler = game.create_profiler(true)
script.on_event(defines.events.on_tick,
  function(e)
    profiler.restart()
    if e.tick-start_tick == 1000 then
      game.print(profiler)
      script.on_event(defines.events.on_tick, nil)
    end
    profiler.stop()
  end
)
Result is after 1000 ticks, the game will print the profiler which in my case is around 1.2ms. Next change the code's first line to be `game.speed = 1000` and run again. Result in my case is around 0.6ms.

I would expect these results to be about the same. There is certainly some variability in the results, but not nearly enough to explain the results being given.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 4332
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [2.0.72] profiler within on_tick giving inconsistent results based on game.speed

Post by boskid »

Welcome in the world where operating system is allowed to reduce cpu frequency based on cpu load causing operations to take longer when cpu is close to being idle. This is not a bug.
Post Reply

Return to “Not a bug”