输入滞后测试仪

Input lag tester

本文关键字:测试仪 滞后 输入      更新时间:2023-10-16

我创建了一个简单的程序,应该能够测试输入延迟。

我的意思是,从你的电脑发送到屏幕的内容到你按下与之相关的键之间的延迟。这是用于测试在线第一人称射击游戏的设置。

该程序的工作原理是以特定的节奏将控制台窗口闪烁为黑白,并要求用户按空格键或任何其他键。它使用getch来确定按键的时间,并使用OpenMP运行与闪烁控制台并行处理getch的功能。

这是否可以作为一个基本的、免费的输入滞后测试,或者如果不是,我应该怎么做才能做到这一点?

//Fdisk's input lag tester
#include <omp.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;
//My global variables. My functions run in parallel so it's easier to use global variables here.
    int i=0;
    long int outp[11];
    long int inpu[11];
//This function takes the input
int inputfunc() {
while(i<11) {
    getch();  //Takes the key input
    inpu[i]=clock(); //Marks the time the key was pressed
    if(inpu[i]-outp[i]>=0 && inpu[i]-outp[i]<5000) //Checks if result is valid
    i++; //Moves the program along so it doesn't blink for eternity
}
return 0;
}
//This function causes the screen to change color
int outputfunc() {
while(i<11) {
    system("color F0"); //Changes screen to white
    outp[i]=clock(); //Marks the time when screen became white
    usleep(400000); //Pause a bit here
    system("color 0F"); //Make the screen black again
    usleep(400000); //Pause again
}
return 0;
}
int main() {
    printf("Fdisk's Input Lag TesternnPress any key when the screen flashes WHITE.     Let it flash a few times before pressing anything, so you can get used to the     rhythm. Using the spacebar is recommended. Be as precise as possible with what you     see on screen. A multicore or multithreading processor is required.n");
    system("pause"); //Sorry my coding is bad
    system("cls"); //Again
 #pragma omp parallel sections //Parallel sections, these run in parallel on a dual core or dual threading machine
 {
     #pragma omp section
     {
         outputfunc(); //The output function, changes the screen's color
     }
     #pragma omp section
     {
         inputfunc();  //The input functions, waits for keypresses
     }
 }
 long int x;
 for(i=0;i<11;i++) {
x=x+(inpu[i]-outp[i]); //Difference between input and output=latency. This adds them up so we can take a mean value.
}
 x=x/11; //This takes the mean value
 x=x*(1000/CLOCKS_PER_SEC); //I think clock is always set to milliseconds but in case it's not
 printf("Your input latency: %imsn",x); //Gives the input latency to the user
 system("pause"); //Pauses the program so it doesn't exit in case not running it from a command line
 usleep(10000000); //Prevents someone from mindlessly pressing space to exit
 system("pause"); //Another redundancy to prevent accidental quitting
 }

我认为您的测试过程甚至不可能提供您试图测量的滞后的粗略估计。这在很大程度上取决于用户的输入,他是否有节奏感,手眼协调性,是否喝过咖啡等等。还要记住,人类很难区分两个相距不到30ms的事件,这会影响结果的准确性。

我不得不在不同的环境中对计算机的滞后性进行类似的评估,但我相信我使用的程序可以适用于您的情况。我需要测量一个系统的端到端延迟:数码相机->图像采集和处理硬件->windows应用程序->显示器。我用相机拍下了闪光灯。然后我用第二台相机(高速)拍摄闪光灯和显示器上的显示。通过第二台相机的视频,我可以测量从原始闪光灯到显示器上的显示之间经过了多少帧。

在你的情况下,你可以带上任何相机,拍摄键盘和显示器,并将视频保存到文件中。你可以敲击键盘并在显示器上观看结果。使用任何视频编辑软件,您都可以测量需要多少帧才能看到结果。当然,精度取决于相机的帧速率,例如,如果你有一台标准的每秒30帧的相机,那么你测得的延迟将是33毫秒的倍数。如果你需要更高的精度,你可以总是使用帧速率更高的相机。