in linq why are subsequent calls of IEnumerable.Intersect so much faster

后端 未结 5 1317
时光说笑
时光说笑 2021-01-19 18:10

while looking at this question C# Similarities of two arrays it was noted that the initial linq call was significantly slower than subsequent calls. What is being cached th

5条回答
  •  感动是毒
    2021-01-19 19:02

    I would expect the first run of any loop to be slower for three reasons:

    1. Code has to be jitted the first time, but not subsequently.
    2. If the executable code run is small enough to fit in cache, then it won't have been evicted, and be faster for the CPU to load.
    3. If the data is small enough to fit in cache, then it won't have been evicted, and be faster for CPU to load.

提交回复
热议问题