YuukiReiya / MyFramework

オンライン制作用。
3 stars 0 forks source link

【Documents】MemoryProfile #105

Open YuukiReiya opened 10 months ago

YuukiReiya commented 10 months ago
        Profiler.BeginSample("Enumerable empty cast ToList");
        var list = Enumerable.Empty<int>().ToList();
        Profiler.EndSample();
スクリーンショット 2023-11-06 0 31 44
Profiler.BeginSample("Create List");
        var temp = new List<int>();
        const int Max = 1000;
        for (int i = 0; i < Max; ++i)
        {
            temp.Add(i);
        }
        Profiler.EndSample();

        Profiler.BeginSample("IEnumerable cast to List");
        IEnumerable e = null;
        e = temp.ToList();
        Profiler.EndSample();

IEnumerableに対して単純にToList()を呼び出した結果。

スクリーンショット 2023-11-06 0 23 30

↑この結果からEnumerable.EmptyではGCAllocは発生していないが、サイズ0でもToListの呼び出しでGCAlloc(40B)が発生することがわかる。 ※Size1000のListに対してToList()を呼び出しeに代入した際には40KBのGCAllocが発生していることもわかる。