Napi
Napi

Reputation: 35

Count how many times a function is called in a time

I need a way to check how many times a function is called in a second. I need to see in 1 second how many times it gets called. How I can do that? I saw tricks about how many times is called.. what I need is how many times is called in 1 second or 5 second

I have an online game, and cheaters did damage speed hacks... The function is called CCharacter::Attack, I need to count how many times per second a normal player can call this function.. based on his character status. And the count how many times per second a hacker call ::Attack

Upvotes: 3

Views: 296

Answers (2)

U. W.
U. W.

Reputation: 418

You would need two things:

  1. A counter where the function can count how often it was called
  2. A timer, which calls another function every second to read out this counter and store the result somewhere else and reset the counter for the next time interval.

Good luck implementing this. Please post the result, this might be very interesting for other people, too!

Upvotes: 0

warchantua
warchantua

Reputation: 1223

If N runs of your func take K seconds, you can calculate "number of time func is called in 1 second" by dividing result=N/K or in 5 sec result5 = 5*N/K

Upvotes: 1

Related Questions