C# - for Loop Freezes at strange intervals

前端 未结 3 1944
猫巷女王i
猫巷女王i 2021-01-23 06:53

I am working on Problem 14 on Project Euler, and my code seems to freeze at random intervals for no apparent reason.

static void Main()
{
    int maxNum = 0;
            


        
3条回答
  •  甜味超标
    2021-01-23 07:31

    I bet that this version doesn't freeze, there's no reason it should do that.

    The Collatz sequences before you hit 1 in the inner while loop are too short to lead to a noticeable delay, and if they would that should always happen at the same numbers.

    If you add console output inside the loop then this may allocate memory, and the pauses you see could be due to garbage collection.

提交回复
热议问题