2015-09-15 14:09:18 +02:00
|
|
|
-- Some benchmarks that aren't really tests, but are included here anyway so
|
|
|
|
-- that we notice if they break.
|
|
|
|
|
2016-03-06 10:20:45 +01:00
|
|
|
local runner = require("_runner")
|
2015-09-15 14:09:18 +02:00
|
|
|
local awful = require("awful")
|
2015-09-27 11:58:35 +02:00
|
|
|
local GLib = require("lgi").GLib
|
|
|
|
local create_wibox = require("_wibox_helper").create_wibox
|
2015-09-15 14:09:18 +02:00
|
|
|
|
2016-01-23 16:08:33 +01:00
|
|
|
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
|
2015-09-15 14:09:18 +02:00
|
|
|
|
|
|
|
local measure, benchmark
|
|
|
|
do
|
|
|
|
local timer_measure = GLib.Timer()
|
|
|
|
measure = function(f, iter)
|
|
|
|
timer_measure:start()
|
2016-02-07 13:04:01 +01:00
|
|
|
for _ = 1, iter do
|
2015-09-15 14:09:18 +02:00
|
|
|
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
|
2016-01-23 16:08:33 +01:00
|
|
|
while time_total < target_time and BENCHMARK_EXACT do
|
2015-09-15 14:09:18 +02:00
|
|
|
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
|
|
|
|
|
2015-09-27 15:07:22 +02:00
|
|
|
local function create_and_draw_wibox()
|
|
|
|
create_wibox()
|
|
|
|
do_pending_repaint()
|
|
|
|
end
|
|
|
|
|
2016-02-07 13:04:01 +01:00
|
|
|
local _, textclock = create_wibox()
|
2015-09-15 14:09:18 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-09-22 00:19:20 +02:00
|
|
|
local function e2e_tag_switch()
|
|
|
|
awful.tag.viewnext()
|
|
|
|
do_pending_repaint()
|
|
|
|
end
|
|
|
|
|
2015-09-27 15:07:22 +02:00
|
|
|
benchmark(create_and_draw_wibox, "create&draw wibox")
|
2015-09-15 14:09:18 +02:00
|
|
|
benchmark(update_textclock, "update textclock")
|
|
|
|
benchmark(relayout_textclock, "relayout textclock")
|
|
|
|
benchmark(redraw_textclock, "redraw textclock")
|
2015-09-22 00:19:20 +02:00
|
|
|
benchmark(e2e_tag_switch, "tag switch")
|
2015-09-15 14:09:18 +02:00
|
|
|
|
2016-03-06 10:20:45 +01:00
|
|
|
runner.run_steps({ function() return true end })
|
2015-12-12 17:42:33 +01:00
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|