简体   繁体   English

为什么C#程序运行速度慢而无需调试

[英]Why does C# Program Run Slower without Debugging

I have a short program to print out all Armstrong Numbers from 10 to 999,999. 我有一个简短的程序可以打印出10至999,999之间的所有阿姆斯壮编号。

When I run in debug mode it finishes in under 1 second. 当我在调试模式下运行时,它会在不到1秒的时间内完成。

When I run without debugging, two command windows are opened. 当我在未调试的情况下运行时,将打开两个命令窗口。 When the second one finally closes, the output is displayed on the first one (this takes about 12 seconds). 当第二个最终关闭时,输出显示在第一个上(大约需要12秒钟)。 However, if I kill the second window from the task manager; 但是,如果我从任务管理器中杀死了第二个窗口; the complete output is displayed in the first window. 完整的输出显示在第一个窗口中。

Also, running the straight .exe files results in the same behavior as running without debugging. 此外,运行直接的.exe文件所产生的行为与未调试运行的行为相同。

Additionally: When I run the straight exe file I am getting around 100 MB of RAM usage (which as far as I know I shouldn't be for a program this small). 另外:当我运行直接exe文件时,我获得了大约100 MB的RAM使用量(据我所知,我不应该用于这么小的程序)。

Here's my code: 这是我的代码:

using System;
public class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine("ARMSTRONG NUMBERS FOUND FROM 10 THROUGH 999999\n");
        int total_armstrong = 0;
        for (int i = 10; i < 1000000; i++)
        {
            int temp = i;
            int k;
            int total = 0;

            for (k = 0; temp != 0; k++) //runs only 6 times maximum    gives me the exponent to use below
                temp /= 10;
            temp = i;
            while (temp != 0) //runs only 6 times maximum
            {
                total += (int)Math.Pow(temp % 10, k);  //calculates the value of each digit raised to the exponent calculated above
                temp /= 10;
            }
            if (total == i)
            {
                Console.WriteLine(total);
                total_armstrong++;
            }
        }
        Console.WriteLine("\nTOTAL NUMBER OF ARMSTRONG NUMBERS FOUND WAS " + total_armstrong);
    }
}

Image of what it looks like while running: Output appears in left window after right closes 运行时的图像:右关闭后,输出出现在左窗口中

有关图片

在此处输入图片说明

I ended up re-installing Visual Studio/Windows and the problem resolved itself. 我最终重新安装了Visual Studio / Windows,问题得以解决。 In the end the nuclear option always solves the problem. 最后,核选择始终可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在C#Visual Studio中,仅调试模式有效。 无法在标准的“不调试运行”中运行 - Only Debugging mode works in C# Visual Studio. Does not run in standard 'Run without Debugging' 为什么我的C程序比它的C#等效速度慢? - Why is my C program slower than its C# equivalent? C# 属性会使程序运行速度变慢吗? - Can C# properties make the program run slower? C#-为什么此循环的第一次迭代比其他循环慢? - C# - Why does the first iteration of this loop run slower than the rest? C#WPF程序在调试中运行,但未经调试不会释放 - C# WPF program runs in debug but not release without debugging C#/ VS2013 - 为什么这段代码没有调试就失败了? - C# / VS2013 - Why does this code fail without debugging? 为什么C#RegexOptions.Compiled会使匹配变慢? - Why does the C# RegexOptions.Compiled makes the match slower? Visual Studio 代码 C# “在不调试的情况下运行”错误 - Visual Studio Code C# "Run Without Debugging" error 为什么这个C#程序在具有24GB内存的64位计算机中会耗尽内存? - Why does this C# program will run out of memory in a 64-bits computer with 24GB of memory? 如何在不挂起程序的情况下运行无限循环? (C#) - How to run an infinite loop without hanging the program? (c#)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM