News for hackers. Stuff that matters.
Re:Operation Costs in CPU Clock Cycles by OskarS on Friday November 11, 2016 @04:52PM (#12934792)
I'm surprised how fast a C function call is. I would have thought that creating a stack frame would be slower than that, (and significantly slower than a floating point division), but I guess not.
Re:Operation Costs in CPU Clock Cycles by dom0 on Friday November 11, 2016 @05:21PM (#12935018)
That's because nothing is created. A function call is just putting some registers on the stack and jumping somewhere else. Stack growth etc. is typically handled implicitly by the OS (if a write on the stack pagefaults more stack memory is allocated).

Contrary to eg. an interpreter where a stack frame would usually be a real, dedicated object that is allocated when a frame is needed.

Re:Operation Costs in CPU Clock Cycles by umanwizard on Friday November 11, 2016 @07:55PM (#12935883)
Creating a stack frame is just updating a register and writing a couple of values to L1 cache.
Re:Operation Costs in CPU Clock Cycles by jheriko on Saturday November 12, 2016 @12:57PM (#12939105)
sometimes not even that. it might just update a single register and write nothing to cache or memory... and that cost might be hidden by out-of-order execution and the parallelism of different units on the CPU, making it effectively zero-cost.