How to create benchmarking event handler method for a scripted entity.

So guys,

As I was coding yesterday, decided to create benchmearking handler for my spinner.

I want to set the sampling time in [ms]

and display the amount of CPU time taken
https://github.com/dvdvideo1234/SpinnerTool/blob/master/lua/entities/sent_spinner.lua#L95 for all the calculations here:

However it seems that the broadcasting event https://github.com/dvdvideo1234/SpinnerTool/blob/master/lua/entities/sent_spinner.lua#L257
does not trigger at 300 [ms] as expected.

Looks like the tame delta in [ms] is calculated wrong here:

But when we see that SysTime() returns the time in seconds, so when I subtract seconds from seconds and multiply by 1000 to get the [ms] and the result is about (0.025),
which is quite small, considering the 300 [ms] for broadcast pass like 300 seconds …

Do any Ideas ?

Your time calculation isn’t wrong: you are thinking it takes much longer than it actually is. The problem is that you aren’t returning true in ENT:Think, so your NextThink call won’t be applied.

Hmm, I do recall putting it at the end of the line though :smiley:

Sorry, it’s very difficult to read the single-line multi-statements on mobile. Just my first point, then.

I do think it takes too long. 300 [ms] are 1/3 of a second, though the trigger event takes about a minute to be called, which is kinda weird LOL.

Found the problem. On Entiti initialization I was inserting the time in [s] instead of [ms]

Fixed now ! Cheers !