Page 1 of 1

How to measure the speed of a script

Posted: 03 Sep 2022 11:19
by LittleBiG
I had two script solution for a problem and I wanted to decide what is the fastest. I added these rows to the beginning and the ending of the script.

Code: Select all

$start = now();
.
.
.
status datediff($start,,"ms")
As you can see, I wanted the result in ms. But in the statusbar only 0 or 1000 appeared. I figured out that maybe the now() function didn't give back the whole time, so I changed the first row to $start_date = now("yyyy-mm-dd hh:nn:ss.fffffff"), copied from the now() section of the help file.
I started to get sensible numbers after that, but once I got a negative one, -49 :?

Then I measured the second script and all numbers became under zero.
Maybe i invented a time travelling script, which goes back in time, and finishes even before started. :veryconfused:

Does anybody have an idea why this is happening? Could it be a bug, or did I use incorrect format?

Edit: I tried to change the datediff to

Code: Select all

status datediff($start_date,now("yyyy-mm-dd hh:nn:ss.fffffff"),"ms");
It seems ok.
I tried to use this one:

Code: Select all

status datediff($start_date,now("yyyy-mm-dd hh:nn:ss.ms"),"ms");
but it gave me incorrect numbers again which is actually because the

Code: Select all

now("yyyy-mm-dd hh:nn:ss.ms")
always gives back milliseconds between 900 and 999. Never lower, I tried it in the address bar.

Now I am super confused.

Edit2: maybe the milllisecond fomat is not the ms but this: now("yyyy-mm-dd hh:nn:ss.fff"). And ms can be used only as an interval, so maybe the solution is something like this:

Code: Select all

$start_date = now("yyyy-mm-dd hh:nn:ss.fff");
.
status datediff($start_date,now("yyyy-mm-dd hh:nn:ss.fff"),"ms");

Re: How to measure the speed of a script

Posted: 03 Sep 2022 23:50
by jupe

Code: Select all

  $start = now("msecs");
  wait 100;
  status now("msecs") - $start;

Re: How to measure the speed of a script

Posted: 05 Sep 2022 14:04
by LittleBiG
Thanks, but something is not right here. When I use your example code and run my script repeatedly, I always get 250 or 266. if I use date format, datediff with "fff" or "fffffff", the numbers can be more varied. As if now("msecs") wouldn't be precise enough...