You should mark this with a specific implementation (e.g. linux ), as the answer certainly depends on the implementation. For now, I will use Linux, as it is the most popular.
With that said, brk theoretically more optimized, and in practice it works on my machine by about 10%. By highlighting one page, this is the time I get:
brk : min 2550 cycles, typical 2650 cyclesmmap : min 2700 cycles, typical 2800 cycles
I remember hearing something along the brk lines that could skip the mmap semaphore lock, which would explain the mismatch.
Note. . I updated these points after setting up my test to make fictitious calls before timing, to make sure that they will all be in the cache.
R ..
source share