廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 70 個閱讀者
 
發表文章 發表投票 回覆文章
  可列印版   加為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.023398 second(s),query:15 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言