Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
140 views
in Technique[技术] by (71.8m points)

c++ - What is the cost of a function call?

Compared to

  • Simple memory access
  • Disk access
  • Memory access on another computer(on the same network)
  • Disk access on another computer(on the same network)

in C++ on windows.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...