What is the cost of a function call?

后端 未结 15 800
天命终不由人
天命终不由人 2020-12-12 22:34

Compared to

  • Simple memory access
  • Disk access
  • Memory access on another computer(on the same network)
  • Disk access on another computer
15条回答
  •  难免孤独
    2020-12-12 23:13

    Hard to answer because there are a lot of factors involved.

    First of all, "Simple Memory Access" isn't simple. Since at modern clock speeds, a CPU can add two numbers faster than it get a number from one side of the chip to the other (The speed of light -- It's not just a good idea, it's the LAW)

    So, is the function being called inside the CPU memory cache? Is the memory access you're comparing it too?

    Then we have the function call will clear the CPU instruction pipeline, which will affect speed in a non-deterministic way.

提交回复
热议问题