Answer the question
In order to leave comments, you need to log in
How much does the logical if operation load the processor in Update?
Let's say I have 1 player script for the whole game. The script hangs only on 1 object in the scene. But, in this script, there will be 40 if checks in the Update method (inte variables and bool in the parameters), how much will this affect performance? And is it possible to do this without fear of optimization problems?
PS checked everything, you can only check these operations in Update, otherwise it will not work correctly
Answer the question
In order to leave comments, you need to log in
let's estimate to the maximum:
- we take 20 cycles for each branch 40 * 20 = 800 cycles for IF
- we will assume that the compiler does not pre-read the cache / registers of local variables, we take 80 integers (int) for 40 checks (8 bytes for x64) (discard bool as a simple one) add a delay (for each in the heap) of a request to AMD in 20 cycles 40 * 80 * 20 = 64000 * 2 = 128000 (read + write without cache)
- add ~10000
total to update the results by the engine: 138,000 cycles * 60 frames per second = 8,328,000 cycles
, this is about 1% load for a 1 GHz mobile workstation, with 1 billion single-cycle operations per second,
the desktop processor immediately works an order of magnitude faster, this is about 0.1% for a single-core 1 GHz 4 GHz
is already 0.02%
(if the compiler is able to pre-read data, then a block of 128,000 reading cycles can be reduced to, say, 1000, this is around 15,000 cycles ~ 0.001%, if the cache of 1-2-3 levels works well in the game system, then maybe 100 cycles for all reading + writing)
that is, your 40 conditions come out, this is from 1% to 0.02% of the budget for a wide range of weak processors
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question