C sharp Program Execution Time And Memory Usage find out
using System;
using System.Diagnostics;
class Watermelon{
public static void Main(string[] args){
// Record memory usage before execution
long memoryBefore = GC.GetTotalMemory(true);
// Start the stopwatch to program measure execution time
Stopwatch stopwatch = Stopwatch.StartNew();
int W = Convert.ToInt32(Console.ReadLine());
if(W%2==0 && W>2){
Console.WriteLine("YES");
}
else{
Console.WriteLine("NO");
}
// Stop the stopwatch and print the elapsed time
stopwatch.Stop();
Console.WriteLine($"Execution Time: {stopwatch.Elapsed.TotalMilliseconds} ms");
// Record memory usage after execution
long memoryAfter = GC.GetTotalMemory(true);
// Print the memory usage
Console.WriteLine($"Memory Usage: {memoryAfter - memoryBefore} bytes");
}
}
//Input Contains W%2==0 && W>2
No comments