Exemplo n.º 1
0
 public static int AddClass(SampleLargeClass cl)
 {
     if (cl.z < 100)
     {
         return(cl.i + cl.j + cl.z);
     }
     else
     {
         return(cl.i % 1000);
     }
 }
Exemplo n.º 2
0
        public static int SampleClass(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}");
                }

                {
                    SampleLargeClass[] sampleClass = new SampleLargeClass[readedValue];
                    for (int i = 0; i < readedValue; i++)
                    {
                        sampleClass[i] = new SampleLargeClass(i, i * 2, i * 3);
                    }


                    int[] tmp = new int[readedValue];

                    var sw = Stopwatch.StartNew();

                    for (int i = 0; i < readedValue; i++)
                    {
                        tmp[i] = AddClass(sampleClass[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 Class {memory12}");
                        Console.WriteLine($"memory in Class {memory22}");
                    }
                }

                currentProc = Process.GetCurrentProcess();
                memory      = GC.GetTotalMemory(true);
                memory2     = currentProc.WorkingSet64;
                if (logMemory)
                {
                    Console.WriteLine($"memory after Class {memory}");
                    Console.WriteLine($"memory after Class {memory2}");
                }
            }
            return(ss);
        }