> Having a frequently called function in a shared library vs. statically linked code could mean the difference of the code executing from CPU's cache or from main memory.
I am under the impression that when process switches the CPU caches are flushed.
No. Only TLBs are flushed (and probably only partially). TLBs are used to associated virtual addresses with physical addresses and memory maps are different per processes.
(That's one reason why it's beneficial to schedule a process on the same CPU if possible - the data is still in the cache)
I am under the impression that when process switches the CPU caches are flushed.