|
using System;
using System.Runtime.InteropServices;
namespace DotNet11Perf
{
//see http://msdn.microsoft.com/en-us/library/9w519wzk.aspx for runtime selection
class Program
{
/*
#if DEBUG
/// Return Type: HANDLE->void*
[DllImport("kernel32.dll", EntryPoint = "GetCurrentProcess")]
private static extern IntPtr GetCurrentProcess();
[DllImport("kernel32.dll", EntryPoint = "GetProcessTimes")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetProcessTimes([In] System.IntPtr hProcess, [Out] out long CreationTime, [Out] out long ExitTime, [Out] out long KernelTime, [Out] out long UserTime);
#endif
*/
private const long TicksPerMiliSecond = TimeSpan.TicksPerSecond / 1000;
static int Main(string[] args)
{
DateTime mainEntryTime = DateTime.UtcNow;
int result = 0;
if (args.Length > 0)
{
DateTime launchTime = System.DateTime.FromFileTimeUtc(long.Parse(args[0]));
long diff = (mainEntryTime.Ticks - launchTime.Ticks) / TicksPerMiliSecond;
/*
#if DEBUG
const long StartOfEpochTicks = 504911232000000000;
Console.WriteLine("Launch time is {0} ticks", launchTime.Ticks - StartOfEpochTicks);
long CreationTime ,ExitTime,KernelTime,UserTime;
if (GetProcessTimes(GetCurrentProcess(), out CreationTime, out ExitTime, out KernelTime, out UserTime))
{
Console.WriteLine("Creation time is {0} ticks, adds {1}", CreationTime, CreationTime - long.Parse(args[0]));
Console.WriteLine("Main EntryTime is {0} ticks, adds {1}", mainEntryTime.Ticks - StartOfEpochTicks, mainEntryTime.Ticks- System.DateTime.FromFileTimeUtc(CreationTime).Ticks);
}
Console.WriteLine("Started in {0} ms",diff);
#endif
*/
result = (int)diff;
}
else
{
System.GC.Collect(2);
System.GC.WaitForPendingFinalizers();
System.Threading.Thread.Sleep(5000);
}
return result;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Decebal Mihailescu is a software engineer with interest in .Net, C# and C++.