Reputation: 10648
i want a real time clock with precision of microseconds how can i do so?
is there any real time clock other than stopwatch;
Upvotes: 11
Views: 12832
Reputation: 29
If you have no internet access and you want real time for timed trial license of software then you can use USB dongle with Real time clock.
Its time calculation is driven by an internal clock which is battery-driven. You can access the time from USB dongle using API functions which come along with these types of dongles.
EX-http://www.senselock-europe.com/en/elite-el-rtc-dongle.html
Upvotes: 0
Reputation: 1
If you want a good time mesurement I think csharp as an high level language might not be a good idea. you could assemble a simple program that taps to RTC and then tie it to your program via a library. That is literally the best possible scenario you can get whith no Object overhang, but it requires some low level know how to put together.
Upvotes: 0
Reputation: 29456
System.Diagnostics.Stopwatch
uses the QueryPerformanceCounter
and QueryPerformanceFrequency
Windows APIs. The resolution is not standard across machines, but generally it's on the order of microseconds (see this KB article for more info).
In Vista/Win7 there is also QueryProcessCycleTime
and QueryThreadCycleTime
which will give you the number of elapsed cycles for your process/thread. This is useful if you want to know only the active time for the process (e.g. time when you weren't switched-out).
Upvotes: 7
Reputation: 1038710
For a high resolution measurements you could use the QueryPerformanceCounter function:
class Program
{
[DllImport("kernel32.dll")]
private static extern void QueryPerformanceCounter(ref long ticks);
static void Main()
{
long startTicks = 0L;
QueryPerformanceCounter(ref startTicks);
// some task
long endTicks = 0L;
QueryPerformanceCounter(ref endTicks);
long res = endTicks - startTicks;
}
}
Upvotes: 3
Reputation: 7673
check this http://www.c-sharpcorner.com/UploadFile/kapilsoni88/Digital_Click08142008142713PM/Digital_Click.aspx and also check this http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx
Upvotes: 2
Reputation: 72638
You want System.Diagnostics.Stopwatch, which can measure time intervals accurately to the microsecond (depending on hardware limitations).
Upvotes: 16