Measuring latency

(I think this has been discussed to death already, but I’m gonna post anyway…)

I’d like to be able to measure the latency of my setup. Because I cannot improve what I cannot measure.

The problem to be measured

I know we have:

  • input latency (how long between the physical button press until the computer detects it)
  • display latency (how long between outputting the video and the image showing on the screen)
  • emulation latency (which can vary per core and per host CPU performance, with many settings and tweaks to minimize it)
  • game engine latency (some games may take a non-zero amount of frames before reacting on-screen)
  • post-processing latency (adding shaders and stuff can take time)
  • operating system latency (which is outside of RetroArch’s control)

Some of these I can reduce by changing some settings. Others I can reduce by replacing my hardware (controllers, display), which can get expensive and isn’t always feasible (e.g. although a CRT has the lowest latency, I’m not getting one).

So, I’d like to be able to measure it. Either the total latency, or the individual parts.

Existing research and tools

There is an official Libretro Doc talking about latency, which suggests several settings that can be tweaked. But it doesn’t explain how to measure the latency.

There is a blog post from Recalbox about input lag and latency, where they even created a tiny one-off gadget called Latency Bro.

I’ve seem MiSTer Laggy project for MiSTer FPGA. It requires a (cheap) dedicated hardware sensor and it can measure the output+display latency. I wonder if RetroArch has anything similar.

I’ve seen An input lag investigation, which modifies a USB game controller to add an LED to a button press. Then it uses a 240fps video recording to manually measure the total latency.

I’ve seen an iOS app called Is It Snappy? and an Android app called Frameskip that are able to measure the time between two frames in a video.

I’ve seen MiSTer Controller Latency website and MiSTer Input Latency sheet and Gamepadla databases of controller latency (both wired and wireless). I’ve also seen software to measure controller latency, but that also requires modifying the controller.

I know there are two lag tests in 240p, from the 240p test suite which is available for most emulated systems.

But so far I’ve seen nothing measuring the audio latency. And I wonder if audio output could also be used to help measuring the other kinds of latency.

Game engine latency

The release notes for RetroArch 1.7.2 include the following:

How to check the amount of lag frames a game has

RetroArch has the ability to pause a core and advance it frame by frame. Perform the following steps to determine the amount of lag frames of a game:

  1. Pause emulation (press ‘p’ button on keyboard).
  2. Press and hold the jump button on the controller.
  3. Advance emulation frame by frame (press ‘k’ button on keyboard) until the character jumps.

The number of k presses before you get a reaction should be the number of lag frames you can safely remove with run ahead.

These steps will eliminate the input and output latency, allowing us to isolate the game engine latency. This is similar to how people create Tool-Assisted Speedruns.

Unfortunately, stochastic parrots are outputting these steps without context and claiming it measures something else.

Objective

I want to know:

  • How much lag does my TV introduce?
  • Does my LCD monitor have less latency than my TV?
  • Does the amount of lag change over different video signals? (e.g. HDMI, DisplayPort, VGA, SCART, …)
  • How much latency do I get in RetroArch on Linux launched from Steam game mode?
  • How much latency do I get in RetroArch on Linux launched from desktop mode?
  • How much latency do I get in RetroArch on Lakka?
  • How much does the latency change on different computers?
  • Can a cheap and underpowered old mini-PC deliver acceptable latency?
  • How much does the latency vary per RetroArch core? Should I have different settings for each core?

Question

Do you know anything else regarding measuring latency? Any other tool? Any other approach? Anything not yet mentioned in this topic? Anything that helps achieving the objective of measuring the actual latency of each setup?

Bonus points for easy/fast/precise solutions, because they let us iterate quicker. While recording a video and then analyzing frame-by-frame is doable, it is also tedious and time-consuming. Having quicker measurements makes it easier to observe the effect of each variable.

1 Like

Fastest and simplest comparison: Make sure mouse is enabled in menu and then simply toggle mouse grab so that you see both menu and OS cursor, and then feel and observe how far behind the menu cursor is.

Another similar method instead of menu is using cores that draw a lightgun/pointer crosshair on the next frame just like the menu. Remote RetroPad in pointer mode will achieve the same results.

Still might be preferable to have a core running so that you can toggle menu between config changes, since some options still have issues coming to life when running menu only…

Mouse movement is superior compared to button press timing and reaction which will fool the brain more easily. Of course this is measuring presentation only, so any lag caused by the display is out of this loop, and so is frame stepping, which is why tests should be done with next frame response cases only.

1 Like

When I need to, I use a phone camera with slow motion record and capture a short clip of the game running while my finger presses the “fire” key in foreground.

the time difference between the fire hit and the game reacting to it is the total latency.

3 Likes

I saw two hardware options there; they look good; for emulation purposes, it would be interesting to capture the differences between the consoles and the emulators/cores.
The LED option is effective, although recording the 16 ms of each reloc cycle at 240 fps may be inaccurate.

Your questions:

  • Flat-screen displays, the response time indicated—12 ms—would be the minimum required to achieve acceptable results. Avoid unknown brands; their response time is usually double or triple that.
    A CRT has no latency unless it has filters, or some other effect.

  • LCD monitor or TV? We usually refer to all flat-screen displays as “LCDs.”

  • The port you use doesn’t cause latency.

  • I don’t know about Steam, but I imagine the game mode works the same way as it does in RetroArch on the desktop or Lakka—they all have it, and it’s enabled.

  • It doesn’t depend on an old computer or mini-PC, but rather on the processor not exceeding the system’s processing capacity.

  • There is no list of minimum requirements, but if the emulator is high-precision, it will require more hardware resources. For example, PCSX ReARMed runs very well on a Pentium Dual Core, whereas Beetle PSX does not run well on a first-generation i7. In these cases, it is necessary to choose an emulator based on the hardware’s capabilities.

I don’t think there’s a way to measure exact latency without dedicated hardware.

Predictive downsampling is used to measure the latency of the original hardware, not the latency caused by emulation on your PC. In most cases, this latency is part of the game’s design; in others, it’s a disaster. It helps eliminate the frames that the console generates natively and improves performance on LCD monitors.

I can give you some tips on how to visually measure input lag (?).
Use the Stella core. The Atari 2600 was the only console that didn’t have input lag.
Use a brand-name controller; generic ones usually cause lag.
If your LCD has a game mode, turn it on; if not, try turning off any automatic processing, contrast, color, noise reduction, or fine-tuning.
No actives shaders.
Use RetroArch with the default settings; don’t enable anything unusual.

1 Like

The slow motion phone camera idea sounds like the most practical way to check this at home. I also found that turning on game mode and keeping shaders off made the delay feel noticeably smaller in fast games.

That will measure how much latency is introduced by RetroArch itself, right? That means controller input latency, OS latency, and display latency cannot be measured by this simple trick. I’m assuming this kind of latency we can probably improve by tweaking the RetroArch settings.

The default hotkey for toggling mouse grab is F11.

If you know, please give suggestions of cores or games that would draw a crosshair.

To be clear, I want to be able to measure the latency of the displays (and other hardware) I already have. Sure, both the TV and the monitor are LCD, but they are from different manufacturers and with different specs. How much differently do they perform?

Also, I assume HDMI and DisplayPort shouldn’t behave any differently when being used in the display native resolution. But how about analog ports (VGA, Composite, Component, SCART)? That requires some processing on the display circuitry to convert the analog signal and scale the image to the native LCD pixels. Does that introduce more latency? Does it vary per port or per manufacturer? I don’t know yet. That’s why I’d like to measure it.

And, of course, I want to measure it on RetroArch and compare it against a MiSTer console. Sure, an FPGA implementation should have no extra lag, but a nicely tuned RetroArch is claimed to also be lag-free. And I cannot tune it if I cannot measure it.

By “game mode”, do you mean the TV’s “game mode”? Sometimes also called “PC mode” or “Computer mode”. Or do you mean something else? Because, yes, that is the most important setting on any TV.

Turning shaders off sounds like a good idea. But, also, having blurry pixels is sometimes desirable, as many older games used dithering for fake transparency or to create more colors. Being able to measure latency is important in the process of learning how much latency do shaders (or non-shader blurring techniques) introduce.

Completely understood. I’ve seen these projects:

  • piLagTester and piLagTesterPRO can measure the display lag, but it requires ordering from that person and e-mailing that person for a copy of the firmware.
  • MiSTer Laggy is relatively cheap (about €13) and can measure the display lag (assuming we already have a MiSTer FPGA).
  • Time Sleuth, as described in RetroRGB, can measure the display lag. It is not cheap (around US$ 135) and seems less useful than MiSTer Laggy. While Time Sleuth only sends an HDMI signal, a MiSTer console can also send different kinds of analog output, and can also play games.
  • Prometheus 82 can measure controller lag (including the OS processing time). It can be built with an Arduino, 3D-printed parts, and some extra electronic components, or bought for around US$ 225.
  • MiSTer FPGA Input Latency Tester can measure the controller lag. It requires disassembling the controller you want to test, and also requires an Arduino, a MiSTer FPGA, and a PC.

And there are certainly other projects. I’m very inclined to give MiSTer Laggy a try, and I wish I had something similar (i.e. simple, easy-to-use, cheap-ish) that could work with RetroArch, so I can measure it against the Steam Deck and also against Lakka on an old computer.

If anyone knows another good hardware project for measuring latency, please mention it here.

Shaders on or off make 0 difference for we on win10 x64 nvidia 4070.
I recorded with a high speed camera many times.

That will measure how much latency is introduced by RetroArch itself, right? That means controller input latency, OS latency, and display latency cannot be measured by this simple trick. I’m assuming this kind of latency we can probably improve by tweaking the RetroArch settings.

It simply reveals the video presentation latency caused by settings (RA and OS driver) as I stated.

If you know, please give suggestions of cores or games that would draw a crosshair.

Ignore game crosshairs unless you want to feel the game lag itself compared to the presentation lag. Many if not all cores that have lightgun emulation also have core options for showing the crosshair. And again Remote RetroPad and the menu are the easiest and surest ones that draw on the next frame.

1 Like

If you have strong hardware, then it makes no difference. I remember back then (my first experience with RetroArch) on RetroPie on a Raspberry Pi 3b, using very complex and advanced (maybe unoptimized) Shaders would have an effect at performance and therefore latency.

1 Like

Sure, not saying the opposite, it was to clarify what could have been taken as a general rule.

The frame by frame pause method helped me separate the game itself from the rest of the setup, because it shows how many frames a game takes to react before the display is involved. I also try the same test on two different cores when I can, since the difference between them can be bigger than I expected.

(I’d edit my previous posts to include these findings, but it seems editing is time-limited.)

I found a few more latency testing tools/projects:

  • OSRTT (Open Source Response Time Tool) and OSLTT (Open Source Latency Time Tool). Requires custom hardware and custom software with custom drivers running on a Windows PC. Thus, it is useless for testing RetroArch.
  • Open-Source-LDAT Teensy is a DIY piece of hardware (Teensy + TEMT6000 ambient light sensor + a tiny OLED display) that requires no custom software, but may require recompiling the firmware yourself. It can either simulate a mouse click itself, or you can wire it to your own mouse. It should work anywhere where a mouse click causes a dark spot on the screen to become bright.
  • m2p-latency is a DIY piece of hardware (Arduino Pro Micro + TEMT6000 ambient light sensor + a tiny OLED display) that simulates a mouse click itself. It requires no custom software. The author designed and built it to measure X11 vs Wayland latency.
  • frameprobe is another piece of hardware that simulates mouse clicks and measures the on-screen response. This one doesn’t have a display and thus seems to require custom Python software on the PC. The author designed and built it to measure X11 vs Wayland latency.
  • gamer-latency-meter uses custom hardware and custom in-browser software to measure the latency of a USB mouse (or keyboard). This is more useful for PC gaming, and less useful for retro gaming.
  • lagmeter is a DIY piece of hardware (Arduino Uno R3 + several extra components) that requires no custom software at all. It can measure the latency of a USB gamepad. It can alternatively simulate a USB gamepad to measure the lag from the simulated button press to the screen. It can even use a Y-cable to read the SVGA signal and measure the latency to the video signal and the latency to the display separately.
  • Blur Busters were once working on an Arduino-based lag meter, but I think it was never completed or released.
  • Leo Bodnar’s HDMI video signal input lag tester, which uses two AA batteries and costs around €125.

Well, that’s enough for today. I’m inclined to try some mouse-to-photon tools (like the m2p-latency). But then I need to find something in RetroArch that reacts to mouse clicks with a bright image. I can probably remap the click to some button, but I’m not sure what game or ROM would be appropriate for this test. Perhaps one of the test screens from the 240p test suite, but I have to investigate. I’ve requested this feature.

1 Like

I think I already answered this, but I’ll be more specific—please correct me if that’s not what you had in mind.

It’s impossible to answer this objectively, because while well-known brands are trustworthy, unknown brands are deceptive. TVs list their response time; 12 ms is the ideal maximum for an acceptable response time with 80% precision when adapting to the console’s 16 ms clock speed. If you want maximum precision and zero lag, you need a monitor with a response time of 6 ms or less.
A TV from an unknown brand or a counterfeit model has a response time of 12 ms, and it could be 24 ms.

Connecting an NTSC/PAL console to an HDMI port using an adapter—which stretches, compresses, and sometimes applies filters—does cause lag.

If you connect the HDMI output at 1080p HD to a CRT using an adapter, the adapter converts the image for a CRT TV, typically downconverting it to 480i. Yes, this causes lag.

If you connect the low-resolution HDMI output to a CRT monitor using an adapter, there is no lag. But to do this, the emulator must be capable of generating low-resolution video output. In RetroArch, you can’t do this by enabling CRTSwitchRes.

In some games, input lag is part of the original design and enhances the experience—for example, in “King of Fighters,” you have 5 frames to attack and only 1 to dodge. In others, it’s a programming disaster, like “Mortal Kombat 1” on the SNES. It has between 5 and 8 random frames of lag—it’s unplayable.

Tienes varias opciones que su resultado dependen del hardware, pero la reducción predictiva de latencia es más radical y genera resultados en cualquier hardware.

Here’s how it works. Let’s say you have an LCD that has a 3 fps delay.

If you have Metal Slug (ARC), which has a 4-frame delay and if you enable predictive latency reduction set to 3 (the same as your LCD), you’ll completely eliminate output lag, and it will behave exactly like the original game on a CRT. If you set it to 4, the LCD’s response time will be faster than that of the CRT itself.

On the other hand, if you have Sonic the Hedgehog (MD), which has a 1-frame delay. You can’t remove more than 1 frame; if your LCD has 3, then it will be 2 fps slower than the CRT, even with the option enabled.

If you connect the PC’s HDMI output via a low-resolution (240p) adapter to a CRT, you’ll completely eliminate the output lag. You’ll only have the input lag and the processing lag. Then you can eliminate the 3 frames in Metal Slug and you’ll have an immediate response—zero lag—but you’ll lose the original design.

The video in the document is a bit abstract. It shows an Atari 2600 core that has NO input lag, connected to a CRT TV that has no output lag, using SwichtRes. O_o