js:性能测试1.1 (#1596)

* js:性能测试1.1

从截图、模板匹配、ocr三个角度评价电脑性能

结果仅作为参考,只能在一定程度上反映当前环境下bgi的运行状态

建议启动bgi后不要执行其他任务就进行测试(如果截图评分低于50,可能bgi没睡醒,建议稍等后再测一次)

* js:锄地一条龙1.4.4

### 1.4.4(2025.08.15)
1.微调了拾取的参数,尝试减少误拾取与遗漏

* js:性能测试1.2

单独测试时得分修正
This commit is contained in:
mno
2025-08-15 17:00:45 +08:00
committed by GitHub
parent 090563bd44
commit 92f1b7e2c0
7 changed files with 87 additions and 42 deletions

View File

@@ -78,6 +78,8 @@
---
### 更新日志
### 1.4.42025.08.15
1.微调了拾取的参数,尝试减少误拾取与遗漏
### 1.4.32025.08.13
1.研究方法进入[沙暴]区域
### 1.4.22025.08.13

View File

@@ -1,4 +1,4 @@
//当前js版本 1.4.3
//当前js版本 1.4.2
//拾取时上下滑动的时间
let timeMoveUp = 500;
@@ -590,7 +590,7 @@ async function runPath(pathFilePath, map_name, whitelistKeywords, blacklistKeywo
}
// 定义一个函数用于执行OCR识别和交互
async function recoginzeAndInteract(imagePath, whitelistKeywords, textxRange, texttolerance) {
async function recognizeAndInteract(imagePath, whitelistKeywords, textxRange, texttolerance) {
async function performOcr(whitelistKeywords, xRange, yRange) {
try {
// 在捕获的区域内进行OCR识别
@@ -706,7 +706,7 @@ async function runPath(pathFilePath, map_name, whitelistKeywords, blacklistKeywo
let centerYTargetText = ocrResult.y + ocrResult.height / 2;
if (Math.abs(centerYTargetText - centerYF) <= texttolerance) {
keyPress("F"); // 执行交互操作
await sleep(2 * trigger); // 操作后暂停 2*trigger 毫秒
await sleep(250); // 操作后暂停 250 毫秒
foundTarget = true;
if ((new Date() - lastPickupTime) > 1000 || ocrResult.text != lastPickupItem) {
log.info(`交互或拾取:"${ocrResult.text}"`);
@@ -724,7 +724,7 @@ async function runPath(pathFilePath, map_name, whitelistKeywords, blacklistKeywo
if (itemName) {
keyPress("F"); // 执行交互操作
log.info(`交互或拾取:"${itemName}"`);
await sleep(2 * trigger + 100); // 操作后暂停 2*trigger+100 毫秒
await sleep(250); // 操作后暂停250 毫秒
foundTarget = true;
}
@@ -752,7 +752,7 @@ async function runPath(pathFilePath, map_name, whitelistKeywords, blacklistKeywo
await keyMouseScript.runFile(`assets/滚轮上翻.json`);
}
if (pickupMode === "模板匹配拾取,默认只拾取狗粮") {
await sleep(Math.round(trigger / 5));
await sleep(Math.round(trigger / 3));
} else {
await sleep(Math.round(trigger));
}
@@ -879,7 +879,7 @@ async function runPath(pathFilePath, map_name, whitelistKeywords, blacklistKeywo
// 根据条件决定是否启动 OCR 检测和交互任务
let ocrTask = null;
if (pickupMode === "ocr拾取默认只拾取狗粮和晶蝶" || pickupMode === "模板匹配拾取,默认只拾取狗粮") {
ocrTask = recoginzeAndInteract(imagePath, whitelistKeywords, textxRange, texttolerance);
ocrTask = recognizeAndInteract(imagePath, whitelistKeywords, textxRange, texttolerance);
}
// 启动泥头车

View File

@@ -1,7 +1,7 @@
{
"manifest_version": 1,
"name": "锄地一条龙",
"version": "1.4.3",
"version": "1.4.4",
"description": "一站式解决自动化锄地支持只拾取狗粮请仔细阅读README.md后使用",
"authors": [
{

View File

@@ -1,59 +1,85 @@
// 主函数
(async function () {
operationMode = settings.operationMode || "截图";
const xRange = parseInt(+settings.xRange || 1920, 10);
const yRange = parseInt(+settings.yRange || 1920, 10);
let startTime = Date.now();
const interval = +settings.interval || 1000;
const timeout = +settings.timeout || 60;
let lastCheck = startTime;
let ocrcount = 0;
let loopCount = 0;
let xRange = parseInt(+settings.xRange || 1920, 10);
let yRange = parseInt(+settings.yRange || 1080, 10);
let interval = +settings.interval || 1000;
let timeout = +settings.timeout || 60;
let dispose = settings.dispose;
const imagePath = "assets/流放.png";
let template = file.ReadImageMatSync(imagePath);
if (operationMode === "截图") {
while (Date.now() - startTime < timeout * 1000) {
let captureRegionScore = 0;
let tempalteMatchScore = 0;
let ocrScore = 0;
await genshin.tpToStatueOfTheSeven();
if (operationMode === "综合测试") {
log.info("开始综合测试,预计用时约30秒");
dispose = true;
timeout = 11;
xRange = 1920;
yRange = 1080;
interval = 1000;
}
if (operationMode === "截图" || operationMode === "综合测试") {
let startTime = Date.now();
let count = 0;
let loopCount = 0;
while (Date.now() - startTime <= timeout * 1000) {
try {
let GameRegion = captureGameRegion();
if (settings.dispose) GameRegion.dispose();
ocrcount++;
if (Date.now() - lastCheck >= interval) {
if (dispose) GameRegion.dispose();
count++;
if (Date.now() - startTime >= interval * (loopCount + 1)) {
loopCount++;
await sleep(1);
lastCheck = Date.now();
log.info(`在第${loopCount}${interval}毫秒内执行了${ocrcount}次截图`);
ocrcount = 0;
log.info(`在第${loopCount}${interval}毫秒内执行了${count}次截图`);
captureRegionScore += count;
count = 0;
}
} catch (error) {
log.error(`运行时发生异常: ${error.message}`);
break;
}
}
captureRegionScore = Math.round(((captureRegionScore * 10 / loopCount) / 33.3) * 100) / 100;
log.info(`截图测试完成,得分${captureRegionScore.toFixed(2)}`);
}
if (operationMode === "模板匹配") {
if (operationMode === "模板匹配" || operationMode === "综合测试") {
let startTime = Date.now();
let count = 0;
let loopCount = 0;
let GameRegion = captureGameRegion();
while (Date.now() - startTime < timeout * 1000) {
while (Date.now() - startTime <= timeout * 1000) {
try {
let recognitionObject = RecognitionObject.TemplateMatch(template, 0, 0, xRange, yRange);
let result = GameRegion.find(recognitionObject);
ocrcount++;
if (Date.now() - lastCheck >= interval) {
count++;
if (Date.now() - startTime >= interval * (loopCount + 1)) {
loopCount++;
await sleep(1);
lastCheck = Date.now();
log.info(`在第${loopCount}${interval}毫秒内执行了${ocrcount}次模板匹配`);
ocrcount = 0;
log.info(`在第${loopCount}${interval}毫秒内执行了${count}次模板匹配`);
tempalteMatchScore += count;
count = 0;
}
} catch (error) {
log.error(`运行时发生异常: ${error.message}`);
break;
}
}
if (settings.dispose) GameRegion.dispose();
if (dispose) GameRegion.dispose();
tempalteMatchScore = Math.round(((tempalteMatchScore * 10 / loopCount) / 3.5) * 100) / 100;
log.info(`模板匹配测试完成,得分${tempalteMatchScore.toFixed(2)}`);
}
if (operationMode === "ocr") {
if (operationMode === "ocr" || operationMode === "综合测试") {
let startTime = Date.now();
let count = 0;
let loopCount = 0;
let GameRegion = captureGameRegion();
while (Date.now() - startTime < timeout * 1000) {
try {
@@ -61,19 +87,31 @@
0, 0,
xRange, yRange
));
ocrcount++;
count++;
} catch (error) {
log.error(`运行时发生异常: ${error.message}`);
break;
}
if (Date.now() - lastCheck >= interval) {
if (Date.now() - startTime >= interval * (loopCount + 1)) {
loopCount++;
lastCheck = Date.now();
await sleep(1);
log.info(`在第${loopCount}${interval}毫秒内执行了${ocrcount}次OCR`);
ocrcount = 0;
log.info(`在第${loopCount}${interval}毫秒内执行了${count}次OCR`);
ocrScore += count;
count = 0;
}
}
if (settings.dispose) GameRegion.dispose();
if (dispose) GameRegion.dispose();
ocrScore = ocrScore;
ocrScore = Math.round((ocrScore * 2 * 10 / loopCount) * 100) / 100;
log.info(`ocr测试完成,得分${ocrScore.toFixed(2)}`);
}
if (operationMode === "综合测试") {
log.info("综合测试结束");
finalScore = (captureRegionScore + tempalteMatchScore + ocrScore) / 3;
log.info(`截图评分为${captureRegionScore.toFixed(2)}`);
log.info(`模板匹配评分为${tempalteMatchScore.toFixed(2)}`);
log.info(`ocr评分为${ocrScore.toFixed(2)}`);
log.info(`综合评分为${finalScore.toFixed(2)}`)
}
})();

View File

@@ -1,7 +1,7 @@
{
"manifest_version": 1,
"name": "性能测试",
"version": "1.0",
"version": "1.2",
"tags": [],
"bgi_version": "0.46.0",
"description": "测测你的",

View File

@@ -1,2 +1,6 @@
运行后将会尝试满负荷循环截图并在日志输出截图次数可在自定义配置选择是否dispose
从截图、模板匹配、ocr三个角度评价电脑性能
结果仅作为参考只能在一定程度上反映当前环境下bgi的运行状态
建议启动bgi后不要执行其他任务就进行测试(如果截图评分低于50可能bgi没睡醒建议稍等后再测一次)

View File

@@ -4,11 +4,12 @@
"type": "select",
"label": "测试项目",
"options": [
"综合测试",
"截图",
"模板匹配",
"ocr"
],
"default": "只截图"
"default": "综合测试"
},
{
"name": "dispose",