mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
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).
This commit is contained in:
committed by
Frans de Jonge
parent
76837c66a7
commit
8005275388
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user