What is the cost of a function call?

后端 未结 15 766
天命终不由人
天命终不由人 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 22:56

    relative timings (shouldn't be off by more than a factor of 100 ;-)

    • memory-access in cache = 1
    • function call/return in cache = 2
    • memory-access out of cache = 10 .. 300
    • disk access = 1000 .. 1e8 (amortized depends upon the number of bytes transferred)
      • depending mostly upon seek times
      • the transfer itself can be pretty fast
      • involves at least a few thousand ops, since the user/system threshold must be crossed at least twice; an I/O request must be scheduled, the result must be written back; possibly buffers are allocated...
    • network calls = 1000 .. 1e9 (amortized depends upon the number of bytes transferred)
      • same argument as with disk i/o
      • the raw transfer speed can be quite high, but some process on the other computer must do the actual work

提交回复
热议问题