简体   繁体   English

计算一次 function 被调用多少次

[英]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.我需要一种方法来检查 function 在一秒钟内被调用了多少次。 I need to see in 1 second how many times it gets called.我需要在 1 秒内查看它被调用了多少次。 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我看到了关于调用多少次的技巧。我需要的是在 1 秒或 5 秒内调用多少次

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.我有一个在线游戏,作弊者破坏了速度黑客...... function 被称为CCharacter::Attack ,我需要根据他的角色状态计算普通玩家每秒可以调用多少次 function..。 And the count how many times per second a hacker call ::Attack并计算黑客每秒调用多少次::Attack

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如果您的 func 的 N 次运行需要 K 秒,您可以通过除以result=N/K或 5 秒result5 = 5*N/K来计算“在 1 秒内调用 func 的次数”

You would need two things:你需要两件事:

  1. A counter where the function can count how often it was called function 可以计算调用频率的计数器
  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.一个计时器,它每秒调用另一个 function 来读出这个计数器并将结果存储在其他地方,并为下一个时间间隔重置计数器。

Good luck implementing this.祝你好运实现这一点。 Please post the result, this might be very interesting for other people, too!请发布结果,这对其他人来说可能也很有趣!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM