Solved

Time stamping events in c# using TimeOfDay results in intervalised results

Posted on 2010-08-20
6
516 Views
Last Modified: 2013-12-17

I wrote a simple console app in c# that outputs record updates of streaming data that can be handled through different real-time APIs . I wanted to timestamp to atleast milisec granularity as per below

 static void OnRecord.Update(Record rec, bool stale, int index, ref System.Array indexArr, ref System.Array valueArr)
        {
           


           for (int i = 0; i < valueArr.Length; i++)
            {
                try
                {
                    Console.WriteLine(rec[index].Name + ":"+ valueArr.GetValue(i) + ":" + DateTime.Now.TimeOfDay);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception: {0}", ex.Message);
                }
            }

the output looked at first glance fine giving name:new value:timestamp as per below

GBL:+20592322:11:41:42.2629255
GBL:+20593312:11:41:42.2629255
GBL:+20594302:11:41:42.4816839
GBL:+20595292:11:41:42.5910631
GBL:+20595677:11:41:43.2629639
GBL:+20596685:11:41:43.2785895
GBL:+20597675:11:41:43.8567367
GBL:+20598402:11:41:46.5599655
GBL:+20599061:11:41:46.5912167
GBL:+20600305:11:41:51.4976551
GBL:+20601096:11:41:51.5132807
GBL:+20601992:11:42:07.8576583
GBL:+20603992:11:42:13.6391303
GBL:+20605992:11:42:13.6391303
GBL:+20608992:11:42:13.6391303
GBL:+20609420:11:42:13.7485095
GBL:+20609520:11:42:13.7485095
GBL:+20609609:11:42:45.8434919
GBL:+20610009:11:42:45.8591175

however on inspection the timestamp are always intervalise by a factor of 0.0156256
Even if I run seperate instances of the app with diffrent record feeds,using diffrent apis for the record event handling then compare the results, the difference in timestamps is stll a factor of this value.
 It's as though running  TimeOfday irrespective if which instance of the app and event  it's calling  only returns results after so many clock cycles.  As the data is coming over the network I also can verify the events through wireshark so know its not the data itself causing this intervalising behaviour.I could understand it if the value was much lower but wouldn't expect it to be 15.6 msec on a modern processor. Perhaps my understanding of the windows Timeofday call  is completely wrong ?
0
Comment
Question by:windymillermc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 33487390
That's standard behavior...

Don't forget that WINDOWS itself gives the illusion of "multi-tasking" by allocating only a small time-slice to each process and its threads.  The "intervalised" gap in-between is probably due to the operation system allowing other processes to do their thing.

If your app was running on specialized hardware where one app was able to monopolize the operating system then perhaps you might see what you expect where the values change smoothly.  (this is theoretical!)

FYI, Windows hasn't been non-preemptive  since version 3.1 back in 1992!
http://en.wikipedia.org/wiki/Preemption_(computing)
http://technet.microsoft.com/en-us/library/cc767883.aspx
0
 

Author Comment

by:windymillermc
ID: 33487457
But if that was the case I would see similar behaviour with wireshark which runs and timestamps packets on the same machine
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 33487514
What language was WireShark written in?  It might lower level optimized code...

.Net is one of the most bloated pieces of framework on the planet!
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Closing Comment

by:windymillermc
ID: 33541016
The answer was correct in why the behaviour was happeing abut it was't a solution as to how to fix the code.
Found the real solution by using DateTimePrecise class written by James Brock
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 33541433
0
 

Author Comment

by:windymillermc
ID: 33545659
ummm well I have now build the project class and used it but it may slightly more granularity but the 15millisec interval is still there. Have you tried it ?
Actually, re-reading the dialogue carefully it does say it has an accuracy of 15 miilisecond but I thought that was a typo as otherwise what's the point of it. So it doesn't do what I expected.
So I'm still searching for a solution
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question