From 800527538868900280710ea298d0f736b3532029 Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Sun, 24 Nov 2024 23:05:34 +0100 Subject: [PATCH] tests: improve PDF benchmarks Factorize and use a proper separate test for each benchmark. Note: only open the 9 fist pages (reduce memory so benchmarks can be run on more limited memory devices, like the Kindle). --- spec/unit/benchmark.lua | 52 +++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/spec/unit/benchmark.lua b/spec/unit/benchmark.lua index ec900ecf9..a7356e4fa 100644 --- a/spec/unit/benchmark.lua +++ b/spec/unit/benchmark.lua @@ -13,31 +13,33 @@ local function logDuration(filename, pageno, dur) end end -describe("PDF rendering benchmark", function() - local sample_pdf = "spec/front/unit/data/sample.pdf" - local doc = DocumentRegistry:openDocument(sample_pdf) - for pageno = 1, math.min(10, doc.info.number_of_pages) do - local secs, usecs = util.gettime() - assert.truthy(doc:renderPage(pageno, nil, 1, 0, 1.0)) - local nsecs, nusecs = util.gettime() - local dur = nsecs - secs + (nusecs - usecs) / 1000000 - logDuration("pdf_rendering.log", pageno, dur) - end - doc:close() -end) +describe("PDF benchmark:", function() -describe("PDF reflowing benchmark", function() - local sample_pdf = "spec/front/unit/data/sample.pdf" - local doc = DocumentRegistry:openDocument(sample_pdf) - doc.configurable.text_wrap = 1 - for pageno = 1, math.min(10, doc.info.number_of_pages) do - local secs, usecs = util.gettime() - assert.truthy(doc:renderPage(pageno, nil, 1, 0, 1.0)) - local nsecs, nusecs = util.gettime() - local dur = nsecs - secs + (nusecs - usecs) / 1000000 - logDuration("pdf_reflowing.log", pageno, dur) + local function benchmark(logfile, reflow) + local sample_pdf = "spec/front/unit/data/sample.pdf" + local doc = DocumentRegistry:openDocument(sample_pdf) + if reflow then + doc.configurable.text_wrap = 1 + end + for pageno = 1, math.min(9, doc.info.number_of_pages) do + local secs, usecs = util.gettime() + assert.truthy(doc:renderPage(pageno, nil, 1, 0, 1.0)) + local nsecs, nusecs = util.gettime() + local dur = nsecs - secs + (nusecs - usecs) / 1000000 + logDuration(logfile, pageno, dur) + end + doc:close() + if reflow then + doc.configurable.text_wrap = 0 + end end - doc:close() - doc.configurable.text_wrap = 0 -end) + it("rendering", function() + benchmark("pdf_rendering.log", false) + end) + + it("reflowing", function() + benchmark("pdf_reflowing.log", true) + end) + +end)