mirror of
https://github.com/awesomeWM/awesome
synced 2024-11-17 07:47:41 +01:00
6d6cf20790
The benchmarks in tests/test-benchmark.lua have two modes. When CI=1 is set in the environment, only a "quick" and less exact test is done. Otherwise, a slower and more exact measurements is taken. This was added so that we do not waste CPU time on travis. However, most of the time the user running "make check" doesn't want exact measurements either. So instead of only being quick when CI=1 is set, this commit changes the logic to always being quick unless BENCHMARK_EXACT=1 is set. Additionally, a message is printed next to the benchmark results so that the user is reminded to set this var if the measurements should actually mean something. Signed-off-by: Uli Schlachter <psychon@znc.in>
80 lines
2.4 KiB
Lua
80 lines
2.4 KiB
Lua
-- Some benchmarks that aren't really tests, but are included here anyway so
|
|
-- that we notice if they break.
|
|
|
|
local awful = require("awful")
|
|
local GLib = require("lgi").GLib
|
|
local create_wibox = require("_wibox_helper").create_wibox
|
|
|
|
local BENCHMARK_EXACT = os.getenv("BENCHMARK_EXACT")
|
|
if not BENCHMARK_EXACT then
|
|
print("Doing quick and inexact measurements. Set BENCHMARK_EXACT=1 as an environment variable when you actually want to look at the results.")
|
|
end
|
|
|
|
local measure, benchmark
|
|
do
|
|
local timer_measure = GLib.Timer()
|
|
measure = function(f, iter)
|
|
timer_measure:start()
|
|
for i = 1, iter do
|
|
f()
|
|
end
|
|
local elapsed = timer_measure:elapsed()
|
|
return elapsed / iter, elapsed
|
|
end
|
|
|
|
local timer_benchmark = GLib.Timer()
|
|
benchmark = function(f, msg)
|
|
timer_benchmark:start()
|
|
local iters = 1
|
|
local time_per_iter, time_total = measure(f, iters)
|
|
-- To improve precision, we want to loop for this long
|
|
local target_time = 1
|
|
while time_total < target_time and BENCHMARK_EXACT do
|
|
iters = math.ceil(target_time / time_per_iter)
|
|
time_per_iter, time_total = measure(f, iters)
|
|
end
|
|
print(string.format("%20s: %-10.6g sec/iter (%3d iters, %.4g sec for benchmark)",
|
|
msg, time_per_iter, iters, timer_benchmark:elapsed()))
|
|
end
|
|
end
|
|
|
|
local function do_pending_repaint()
|
|
awesome.emit_signal("refresh")
|
|
end
|
|
|
|
local function create_and_draw_wibox()
|
|
create_wibox()
|
|
do_pending_repaint()
|
|
end
|
|
|
|
local wb, textclock = create_wibox()
|
|
|
|
local function relayout_textclock()
|
|
textclock:emit_signal("widget::layout_changed")
|
|
do_pending_repaint()
|
|
end
|
|
|
|
local function redraw_textclock()
|
|
textclock:emit_signal("widget::redraw_needed")
|
|
do_pending_repaint()
|
|
end
|
|
|
|
local function update_textclock()
|
|
textclock:emit_signal("widget::updated")
|
|
do_pending_repaint()
|
|
end
|
|
|
|
local function e2e_tag_switch()
|
|
awful.tag.viewnext()
|
|
do_pending_repaint()
|
|
end
|
|
|
|
benchmark(create_and_draw_wibox, "create&draw wibox")
|
|
benchmark(update_textclock, "update textclock")
|
|
benchmark(relayout_textclock, "relayout textclock")
|
|
benchmark(redraw_textclock, "redraw textclock")
|
|
benchmark(e2e_tag_switch, "tag switch")
|
|
|
|
require("_runner").run_steps({ function() return true end })
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|