C
C#15mo ago
Joseph

❔ Different Runtimes

Hello, my code is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;

namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < 1000; i++)
{
Console.WriteLine(i);
}
watch.Stop();
Console.WriteLine($"Execution Time: {watch.ElapsedMilliseconds} ms");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;

namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < 1000; i++)
{
Console.WriteLine(i);
}
watch.Stop();
Console.WriteLine($"Execution Time: {watch.ElapsedMilliseconds} ms");
}
}
}
when i run this code with writing dotnet run i get 130 ms when i run run it f5 which is "start debugging" i get 20 ms and when i run it ctrl + f5 which is "run without debugging" i get 13 ms can i ask why different speeds?
3 Replies
Thinker
Thinker15mo ago
Don't do this, use Benchmark.NET if you need accurate benchmarking/run times
Developful
Developful15mo ago
theres a difference between release and debug due to debugging symbols and stuff like that. Basically, C# adds extra stuff to the compiled code so when you're debugging, its a nice and much more pleasant experience, while release is clean of those. as for dotnet run.. i'm not sure why but from what i've gathered, it has to do with building the project again, i can't find anything else on this though you can notice the difference between release and debugging while trying to evaluate certain expressions some variables might be missing even though they are there, some functions, etc
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server