广告广告
  加入我的最爱 设为首页 风格修改
首页 首尾
 手机版   订阅   地图  繁体 
您是第 103 个阅读者
 
发表文章 发表投票 回覆文章
  可列印版   加为IE收藏   收藏主题   上一主题 | 下一主题   
冷场馆女仆长 会员卡
个人头像
个人文章 个人相簿 个人日记 个人地图
特殊贡献奖
头衔:一位兴趣使然的伺服主一位兴趣使然的伺服主
特约版主
级别: 特约版主 该用户目前不上站
版区: CS教学区
推文 x199 鲜花 x477
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片
推文 x1
[插件] AMXX简易函数速度分析器  (测试AMXX执行速度利器)
【插件资讯】

插件来源: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秒,
恭喜你,无用的冷知识增加了表情

不过提醒下各位:
分析器得出的结果有可能因不同环境、不同参数、或其他因素而有所影响,
所以测试结果(尤其是一些差距不太大的数字)大家就只当作一个参考就好表情


本帖包含附件
zip AMXXEasyProfiler.zip   (2025-05-02 23:55 / 57 KB)  
说明: 0.01版本
下载次数:0
zip EasyProfiler源码.zip   (2025-05-02 23:55 / 68 KB)   下载次数:0


[ 此文章被冷场馆女仆长在2025-05-03 11:42重新编辑 ]



我只是一个兴趣使然的Server主.
献花 x2 回到顶端 [楼 主] From:未知地址 | Posted:2025-05-02 23:55 |

首页  发表文章 发表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.014233 second(s),query:15 Gzip disabled
本站由 瀛睿律师事务所 担任常年法律顾问 | 免责声明 | 本网站已依台湾网站内容分级规定处理 | 连络我们 | 访客留言