In some large-scale C++ projects, the Debug version is almost useless, such as some game engines UnrealEngine, Ogre3d, etc. Because the Debug version of the program is too stuck to run, it is almost unusable. But when I was developing a C# program, I was surprised to find that the difference in experience between the Debug version and the Release version of the C# application was not so great that it was impossible to distinguish between debug and release. why?
// test C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApp21
{
internal class Program
{
static void DoSomething()
{
StringBuilder builder = new StringBuilder();
for(int i=0;i<10000000; ++i)
{
builder.Append(i.ToString());
}
Console.WriteLine($"{builder.ToString().Length}");
}
static void Main(string[] args)
{
#if DEBUG
Console.WriteLine("DEBUG:");
#else
Console.WriteLine("Release:");
#endif
Stopwatch sw = Stopwatch.StartNew();
DoSomething();
Console.WriteLine(sw.Elapsed.ToString());
}
}
}
DEBUG: 68888890 00:00:00.9831842
Release: 68888890 00:00:00.8958183
// test cpp code
#include <iostream>
#include <string>
#include <boost/progress.hpp>
void DoSomething()
{
std::string str;
char buf[64];
for (int i = 0; i < 1000000; ++i)
{
sprintf_s(buf, "%d", i);
str.append(buf);
}
std::cout << str.size() << std::endl;
}
int main()
{
#ifdef _DEBUG
printf_s("DEBUG:");
#else
printf_s("RELEASE:");
#endif
boost::progress_timer timer;
DoSomething();
}
DEBUG:5888890 0.33 s
RELEASE:5888890 0.06 s