Link to home
Create AccountLog in
Avatar of Eimund

asked on

TDateTime::CurrentDateTime - problem with accurate time in milliseconds


I'm makeing a log where I need a timestamp for each log. The problem is the accuracy of the milliseconds when I request consecutive timestamps. In my log, when requesting a new timestamp within 100ms, it seems that TDateTime::CurrentDateTime jumps 10ms instead of 1ms. A piece of my selfmade log is shown below. As you se least significant millisecond digit is 3, and the change occures from the is the second least significant millisecond digit.

I call the function AddEvent (code snipp attached) from a multithreaded environment by using TThread::Synchronize.

Do any one know the cause of this? And if so, is there a way to get 1ms accuracy of the timestamp?

Eimund Smestad

18.07.2008 09:09:07.073      Data written to Interface 1
0X00 0X9C 0X34 0X3B 0X06 0X6C 0X9F 0XB1 0X7E 0XB7 0XBF 0X55 0XFA 0X40 0XC9 0XD9 0X56 0X96 0XC6 0X3C 0X34 0X3D 0XBA 0X9E 0X4F 0XF5

18.07.2008 09:09:07.083      IN-datalength on interface 1 is set to 26 bytes

18.07.2008 09:09:07.083      OUT-datalength on interface 1 is set to 32 bytes

18.07.2008 09:09:07.103      Data written to Interface 1
0X00 0X5E 0X56 0XB2 0XEE 0X89 0X95 0X05 0X2B 0X16 0X80 0X97 0X95 0X34 0X31 0X80 0X45 0X22 0XE2 0XAA 0X2D 0X81 0XB5 0X83 0X66 0X18 0XCA 0X92 0XA8 0XA6 0X80 0X88

18.07.2008 09:09:07.113      IN-datalength on interface 1 is set to 32 bytes

void CUSB::Log::AddEvent(AnsiString event, bool blanckline)
	AnsiString text;
	tid = tid.CurrentTime();
	LongTimeFormat = "hh:nn:ss.zzz";
	text = "" + tid.CurrentDateTime() + "\t" + event;

Open in new window

Avatar of cup

The problem is how long Log->Lines->Add takes.  If that has to do any new/malloc/realloc or printf/cout, there is very little chance of getting accurate ms timings.  Best stick to seconds.

If it is just dumping it into an array which is picked up by a logger task you might get more accurate timings.
Avatar of itsmeandnobodyelse
Flag of Germany image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account