Skip to content

Commit 06c3d90

Browse files
committed
TOOLS/command-test.lua: add test to measure responsiveness
This test measures how long commands take to run while the main thread is being hammered with async commands. I get the following result: [command_test] responsiveness baseline: 0.235ms [command_test] responsiveness while spawning subprocesses: 5.226ms
1 parent 47fc815 commit 06c3d90

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

TOOLS/lua/command-test.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,26 @@ mp.observe_property("vo-configured", "bool", function(_, v)
108108
mp.command_native({_flags={"async"}, name = "subprocess",
109109
playback_only = false, args = {"sleep", "inf"}})
110110

111+
-- Responsiveness test. First we test how long a synchronous command took
112+
-- without asynchronous commands being dispatched, then we test how long it
113+
-- takes while asynchronous commands are being dispatched.
114+
local function test_responsiveness()
115+
local baseline_start = mp.get_time()
116+
mp.command_native({"expand-text", ""})
117+
print(string.format("responsiveness baseline: %.3fms",
118+
(mp.get_time() - baseline_start) * 1000))
119+
120+
for _ = 1, 1000 do
121+
mp.command_native_async({name = "subprocess", args = {"true"}},
122+
function() end)
123+
end
124+
125+
local loaded_start = mp.get_time()
126+
mp.command_native({"expand-text", ""})
127+
print(string.format("responsiveness while spawning subprocesses: %.3fms",
128+
(mp.get_time() - loaded_start) * 1000))
129+
end
130+
111131
-- Rapidly dispatching many subprocesses asynchronously must not block the
112132
-- main thread. If it takes multiple seconds we're blocking the main thread.
113133
local rapid_done = 0
@@ -119,6 +139,12 @@ mp.observe_property("vo-configured", "bool", function(_, v)
119139
if rapid_done == 1000 then
120140
print(string.format("done rapid subprocess dispatch in %.3fms",
121141
(mp.get_time() - rapid_start) * 1000))
142+
-- Responsiveness test needs to be called from the final
143+
-- callback of the rapid dispatch test, in case it does
144+
-- block the main thread. This is the clearest way to ensure
145+
-- this test is done before we move on to the responsiveness
146+
-- test.
147+
test_responsiveness()
122148
end
123149
end)
124150
end

0 commit comments

Comments
 (0)