질문 글을 올릴때 부실하게 올려서 글을 다시 작성합니다.
재현 가능한 코드 없이 질문들을 남겨서 죄송합니다.
폼에는 버튼1과 리치텍스트박스1만 있습니다.
버튼을 눌러 시간 측정을 하면 할 수록
소요 시간이 조금씩 점점 늘어납니다.
cpu클럭에 따라 소요시간이 들죽날죽 달리지기는건 당연하지만 
스탑워치로 시간 측정을 하면 할 수록 소요시간이 점점 불어나네요.
static Stopwatch stopwatch = new Stopwatch();
        static MyClass[] myArray = new MyClass[1_000_000];
        public class MyClass
        {
            public int cValue = 0;
        }
        public Form2()
        {
            InitializeComponent();
        }
        private void Form2_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 1_000_000; i++)
            {
                myArray[i] = new MyClass();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            stopwatch.Reset();
            stopwatch.Start();
            long startTick = stopwatch.ElapsedTicks;
            for (int k = 0; k < 2000; k++)
            {
                for (int i = 0; i < 1_000_000; i++)
                {
                    MyClass tmp = myArray[i];
                    if (tmp.cValue % 2 == 0)
                        tmp.cValue += 2;
                    if (tmp.cValue % 3 == 0)
                        tmp.cValue += 3;
                    if (tmp.cValue % 4 == 0)
                        tmp.cValue += 4;
                    if (tmp.cValue % 5 == 0)
                        tmp.cValue += 5;
                    if (tmp.cValue % 10 == 0)
                        tmp.cValue -= 10;
                    tmp.cValue += 1;
                    tmp.cValue += i;
                    tmp.cValue -= i;
                    tmp.cValue *= i;
                    if (tmp.cValue != 0)
                        tmp.cValue /= i;
                }
            }
            long endTick = stopwatch.ElapsedTicks;
            stopwatch.Stop();
            long ctime = endTick - startTick;
            richTextBox1.Text += string.Format("소요시간 {0:#,#}", ctime) + Environment.NewLine;
            button1.Enabled = true;
        }
        
        
                    
                    
                    
                    
                    
    
                    
                    
                    
                    
                    
                
                    [최초 등록일: ]
                    [최종 수정일: 2/19/2022]