【插件资讯】插件来源:
https://dev-cs.ru/r...s/987/使用指令:
1.下载并解压缩到cstrike资料夹
2.打开cstrike\addons\amxmodx\configs\modules.ini
3.开新行分别加上 : easyprofiler
安装路径:如上
【插件介绍】你有没有在使用某条函数时好奇它的执行速度到底有多快?
虽然现今的电脑设备运行AmxModX根本就轻轻松松,
但这并不能压住我们的好奇心,尤其是AMXX模块有很多相似的功能,
「哪种函数更快」「哪种写法效率较好」这些疑问不停冒出来

虽AMXX1.10内置了performance monitor,
但显示的时间并不仔细,而且结果很易受环境影响,

它也不能只测试部分程式码,使用时要把整个插件加上debug

不过没办法,毕竟它本来就不是设计用来测试速度

而这个模块可以显示更详细的执行时间,
你可以从easy_profiler.inc查看可使用的函数:
复制程式
/**
* Pushes current time in the profiler virtual stack
*
* @noreturn
*/
native ep_start();
/**
* Pops a time from the profiler virtual stack, calculates return value and
* prints log message accroding to fmt if it was set.
*
* @param count Divisor for time (iterations count)
* @param fmt C style format, where "%f" stands for time
*
* @return Elapsed time for `count` operations +-correction value
*/
native Float:ep_end(count = 1, fmt[] = "");
/**
* Pauses execution
*
* @param time Time in seconds
*
* @return Return value of linux select(...)
*/
native ep_sleep(Float:time);
/**
* Sets global correction value
*
* @param time Correction value
*
* @noreturn
*/
native ep_set_correction(Float:time);
/**
* Pops a time from the profiler virtual stack, sets correction, calculates return value,
* prints log message according to fmt if it was set and correction >0.0.
*
* @param count Divisor for time (iterations count)
* @param fmt C style format, where "%f" stands for time
*
* @return Correction value
*/
native ep_end_and_set_correction(count = 1, fmt[] = "");
/**
* Dummy call that returns immediately
*
* @noreturn
*/
native ep_dummy_call();
/**
* Automatically calibrate easyprofiler.
*
* @param n Number of iterations
*
* @noreturn
*/
stock ep_calibrate(n = 50000)
{
ep_start();
for(new i = 0; i < n; ++i)
{
ep_start();
ep_end();
}
ep_end_and_set_correction(n, "Correction is set to %.17f");
}
而这是使用方法:
复制程式
#include <amxmodx>
#include <easy_profiler>
public plugin_init()
{
ep_calibrate(); //重新校准分析器
ep_start();
for (new i = 0; i < 10000; i++) //重复执行10000次,以获得较平均的结果
{
abs(-114514); //要测试的函数
}
ep_end(1, "abs(-114514) time: %.17f"); //显示测试后得出的时间
}
将上面的源码编译成amxx后放在伺服器上执行就好
测试结果:
从图中我们可以看到,
abs(-114514) 这次在这插件执行10000次总消耗时间为0.000045519456秒,
恭喜你,无用的冷知识增加了
不过提醒下各位:
分析器得出的结果有可能因不同环境、不同参数、或其他因素而有所影响,
所以测试结果(尤其是一些差距不太大的数字)大家就只当作一个参考就好
