How to measure the speed of a script

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

How to measure the speed of a script

Post 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");

jupe
Posts: 3578
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: How to measure the speed of a script

Post by jupe »

Code: Select all

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

LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: How to measure the speed of a script

Post 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...
To see the attached files, you need to log into the forum.

Post Reply