Recent

Author Topic: epiktimer on different computers  (Read 3483 times)

bd4kc

  • New Member
  • *
  • Posts: 46
epiktimer on different computers
« on: December 10, 2020, 01:02:00 pm »
Code: Pascal  [Select][+][-]
  1. procedure TFormMain.FormCreate(Sender: TObject);
  2. begin
  3.     ept1:= TEpikTimer.Create(nil);
  4.     ept1.StringPrecision := 6;
  5.     ept1.TimebaseSource := SystemTimebase;
  6.     ept1.CorrelationMode := OnTimebaseSelect;
  7. end;
  8.  
  9. procedure TFormMain.Timer1Timer(Sender: TObject);
  10. var  //941503302: DEV:10045x0.1mS max010045 min000010
  11.   s:string;
  12.   i,j:Int64;
  13.   mi,mj:Int64;
  14. begin
  15.   mi:=maxdev;mj:=mindev;
  16.   i:=ept1.GetSystemTicks+500;
  17.   j:=i-ttt0;
  18.   if(j>mi) then mi:=j else mi:=maxdev;
  19. if(j<mj) then mj:=j else mj:=mindev;
  20. s:=inttostr((i) div 1000)+':'+ ' DEV:'+rightstr('00000'+inttostr(j div 1000),5)+'x0.1mS'+ ' max'+rightstr('0000'+inttostr(mi div 1000),6)+ ' min'+rightstr('0000'+inttostr(mj div 1000),6) +chr($0d)+chr($0a);
  21.     MemoText.Append(s);
  22.   ttt0:=i;    maxdev:=mi;mindev:=mj;
  23.   sleep(30);
  24. //  if(mindev<30000) then mindev:=100000;
  25. end;
  26.  
  27.  
On two computers that are also Win10 64-bit, the results are different
« Last Edit: December 10, 2020, 01:18:19 pm by marcov »

bd4kc

  • New Member
  • *
  • Posts: 46
Re: epiktimer on different computers
« Reply #1 on: December 10, 2020, 01:10:25 pm »
Code: Pascal  [Select][+][-]
  1.  
procedure TFormMain.FormCreate(Sender: TObject);
begin
    ept1:= TEpikTimer.Create(nil);
    ept1.StringPrecision := 6;
    ept1.TimebaseSource := SystemTimebase;
    ept1.CorrelationMode := OnTimebaseSelect;
end;

procedure TFormMain.Timer1Timer(Sender: TObject);
var  //941503302: DEV:10045x0.1mS max010045 min000010
  s:string;
  i,j:Int64;
  mi,mj:Int64;
begin
  mi:=maxdev;mj:=mindev;
  i:=ept1.GetSystemTicks+500;
  j:=i-ttt0;
  if(j>mi) then mi:=j else mi:=maxdev;
if(j<mj) then mj:=j else mj:=mindev;
s:=inttostr((i) div 1000)+':'+ ' DEV:'+rightstr('00000'+inttostr(j div 1000),5)+'x0.1mS'+ ' max'+rightstr('0000'+inttostr(mi div 1000),6)+ ' min'+rightstr('0000'+inttostr(mj div 1000),6) +chr($0d)+chr($0a);
    MemoText.Append(s);
  ttt0:=i;    maxdev:=mi;mindev:=mj;
  sleep(30);
//  if(mindev<30000) then mindev:=100000;
end;
On two computers that are also Win10 64-bit, the results are different

jamie

  • Hero Member
  • *****
  • Posts: 7587
Re: epiktimer on different computers
« Reply #2 on: December 10, 2020, 01:25:53 pm »
its about speed of your computer.

Timers run in the background and different computers process the task it needs faster/Slower but the timer keeps running at the same space in the background.

 The problem apparently is your system differs in performances
The only true wisdom is knowing you know nothing

bd4kc

  • New Member
  • *
  • Posts: 46
Re: epiktimer on different computers
« Reply #3 on: December 10, 2020, 01:41:45 pm »
Thanks for the reply,I tried to measure TTimer with Epiktimer , Does the epiktimer start automatically in the IDE environment, and after leaving the IDE, the Start method is required?

jamie

  • Hero Member
  • *****
  • Posts: 7587
Re: epiktimer on different computers
« Reply #4 on: December 10, 2020, 02:25:00 pm »
The tick timer in the OS starts when it boots.

It is the number of ticks since it has started.

The control you are playing with most likely simply offsets the current reading of the OS and just uses that as a starting base.

The real value can be gotten using the GetTicks64

There are also performance timers in the system.

QueryPerformanceCounter
QyeryPerformanceFrequency

basically these are hardware counters if your system supports them. Most likely your system will support them because that is basically a given these days

The Counter is the current value if its supported.

The frequency is the counts per second if your system supports hardware counters etc.

So basically you can get both the current count and the number of counts per second from your hardware clock..

keep in mind that because windows is a tasking system, the COUNT value will most likely vary all over the place since the last time it was read because the system gets busy and puts your app on hold and by the time your app gets to look at it, the counts have elapsed in random size.

I don't know what it is that sparks your interest but maybe you are looking for a precision timer event?

I think the best you can do is using a media timer if that is the case, windows puts high priority on your app with that one.

The only true wisdom is knowing you know nothing

bd4kc

  • New Member
  • *
  • Posts: 46
Re: epiktimer on different computers
« Reply #5 on: December 10, 2020, 04:10:14 pm »
Hi, I'll keep experimenting and find out why. I want to process tcp/ip traffic at relatively accurate intervals, but high-priority timers, priority, don't make sense if they affect the communication thread, so I don't think there's a high-priority timer, just know the accuracy of the timer.

Thaddy

  • Hero Member
  • *****
  • Posts: 18764
  • To Europe: simply sell USA bonds: dollar collapses
Re: epiktimer on different computers
« Reply #6 on: December 10, 2020, 06:56:37 pm »
That looks like a wrong approach since both TCP and UDP come with a timestamp when the message was send.
You should only compare times, not use a timer.....you should use  now() and the package timestamp.
That will give you the values in milliseconds, on some platforms microseconds.
« Last Edit: December 10, 2020, 07:01:35 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

bd4kc

  • New Member
  • *
  • Posts: 46
Re: epiktimer on different computers
« Reply #7 on: December 10, 2020, 07:00:46 pm »
The test code, on the A computer, getsystemticks and elapsed are the same results, and on the B computer it is significantly different.

Thaddy

  • Hero Member
  • *****
  • Posts: 18764
  • To Europe: simply sell USA bonds: dollar collapses
Re: epiktimer on different computers
« Reply #8 on: December 10, 2020, 07:04:02 pm »
The test code, on the A computer, getsystemticks and elapsed are the same results, and on the B computer it is significantly different.
That is a hardware issue, not related to any programming language.
Note that this can also be caused by modern processors throttling between load.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

bd4kc

  • New Member
  • *
  • Posts: 46
Re: epiktimer on different computers
« Reply #9 on: December 10, 2020, 07:06:39 pm »
That looks like a wrong approach since both TCP and UDP come with a timestamp when the message was send.
You should only compare times, not use a timer.....you should use  now() and the package timestamp.
That will give you the values in milliseconds, on some platforms microseconds.

I want to measure the time interval between arrival and issue of tcp packets and process the data within a defined time. So re-create the wheels to see how accurate the windows timer is.

Thaddy

  • Hero Member
  • *****
  • Posts: 18764
  • To Europe: simply sell USA bonds: dollar collapses
Re: epiktimer on different computers
« Reply #10 on: December 10, 2020, 07:10:29 pm »
I want to measure the time interval between arrival and issue of tcp packets and process the data within a defined time. So re-create the wheels to see how accurate the windows timer is.
That is a contradiction in terms.
1: do you want to measure delay?
2: do you want to measure timer accuracy?

The latter depends on scale.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

MarkMLl

  • Hero Member
  • *****
  • Posts: 8547
Re: epiktimer on different computers
« Reply #11 on: December 10, 2020, 10:53:51 pm »
That looks like a wrong approach since both TCP and UDP come with a timestamp when the message was send.
You should only compare times, not use a timer.....you should use  now() and the package timestamp.
That will give you the values in milliseconds, on some platforms microseconds.

I'm afraid that I'm not entirely comfortable with that. Now granted that my recent experience doesn't include Windows, but I don't think you'll get timestamps out of the standard (Berkeley sockets) API unless you either explicitly ask for them as an IP (?) option or you use something like PCAP to get timestamped packets. In addition Now() isn't- IMO- a good choice for precision timing since it's a floating point number, and the larger it gets relative to its epoch the less precise it is.

However I agree that OP's requirement... needs refinement. In particular he needs to understand that a modern processor has hardware timers independent of any thread, that these timers are CPU-specific, and that since many systems these days have multiple CPUs and most have multiple cores and/or support for hardware threads they're likely to be oblivious to timer-update interrupts etc.

He also needs to appreciate that most systems have so many hardware and software layers in between their network socket and application code that it's extremely difficult to measure network latency etc. in software, even if one or more of the cooperating systems is known to handle e.g. ping (ICMP echo) responses in hardware or the lowest levels of device driver.

MarkMLl

MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

bd4kc

  • New Member
  • *
  • Posts: 46
Re: epiktimer on different computers
« Reply #12 on: December 11, 2020, 05:38:31 am »
Simply interested in epikTimer,
Try three more computers, getsystemticks and elapse are the same results. It's strange that only my computer doesn't (15ms vs 50ms, 26ms vs 100ms, 245ms vs 1000ms). It's All Win10 64bits, and the versions aren't very new. The operating system has not been upgraded since it was installed because it is not connected to the Internet.

bd4kc

  • New Member
  • *
  • Posts: 46
Re: epiktimer on different computers
« Reply #13 on: December 11, 2020, 07:16:57 am »
Without specifically picking computers bought from the market, the value of getsystemticks varies so much that it feels uncertain. :(


The test code, on the A computer, getsystemticks and elapsed are the same results, and on the B computer it is significantly different.
That is a hardware issue, not related to any programming language.
Note that this can also be caused by modern processors throttling between load.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12706
  • FPC developer.
Re: epiktimer on different computers
« Reply #14 on: December 11, 2020, 12:25:55 pm »
Simply interested in epikTimer,
Try three more computers, getsystemticks and elapse are the same results. It's strange that only my computer doesn't (15ms vs 50ms, 26ms vs 100ms, 245ms vs 1000ms). It's All Win10 64bits, and the versions aren't very new. The operating system has not been upgraded since it was installed because it is not connected to the Internet.

Is the weird computer old, like core2 or P4 ?   Since somewhere close to the introduction of the i3/i5/i7 designation of processors, there was iirc a guaranteed high frequency high performance timer integrated into the CPU's uncore. (1MHz?)

 

TinyPortal © 2005-2018