public static int AddStruct(SampleLargeStruct cl) { if (cl.z < 100) { return(cl.i + cl.j + cl.z); } else { return(cl.i % 1000); } }
public static int SampleStruct(int readedValue) { int ss = 0; Process currentProc; long memory, memory2; unchecked { currentProc = Process.GetCurrentProcess(); memory = GC.GetTotalMemory(true); memory2 = currentProc.WorkingSet64; if (logMemory) { Console.WriteLine($"memory before {memory}"); Console.WriteLine($"memory before {memory2}"); } { SampleLargeStruct[] sampleStruct = new SampleLargeStruct[readedValue]; for (int i = 0; i < readedValue; i++) { sampleStruct[i] = new SampleLargeStruct(i, i * 2, i * 3); } int[] tmp = new int[readedValue]; var sw = Stopwatch.StartNew(); for (int i = 0; i < readedValue; i++) { tmp[i] = AddStruct(sampleStruct[i]); } for (int i = 0; i < tmp.Length; i++) { ss += tmp[i]; } if (logTimeInternal) { Console.WriteLine($"{ss} {sw.Elapsed}"); } Process currentProc2 = Process.GetCurrentProcess(); long memory12 = GC.GetTotalMemory(true); long memory22 = currentProc2.WorkingSet64; if (logMemory) { Console.WriteLine($"memory in Struct {memory12}"); Console.WriteLine($"memory in Struct {memory22}"); } currentProc = Process.GetCurrentProcess(); memory = GC.GetTotalMemory(true); memory2 = currentProc.WorkingSet64; if (logMemory) { Console.WriteLine($"memory after Struct {memory}"); Console.WriteLine($"memory after Struct {memory2}"); } } return(ss); } }