forked from koreader/koreader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.lua
55 lines (44 loc) · 1.62 KB
/
benchmark.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-- performance benchmark utility
-- usage: ./luajit tools/benchmark.lua test/sample.pdf
require "defaults"
package.path = "common/?.lua;rocks/share/lua/5.1/?.lua;frontend/?.lua;" .. package.path
package.cpath = "common/?.so;common/?.dll;/usr/lib/lua/?.so;rocks/lib/lua/5.1/?.so;" .. package.cpath
local DataStorage = require("datastorage")
--G_reader_settings = require("docsettings"):open(".reader")
G_reader_settings = require("luasettings"):open(
DataStorage:getDataDir().."/settings.reader.lua")
-- global einkfb for Screen (do not show SDL window)
einkfb = require("ffi/framebuffer")
einkfb.dummy = true
local DocumentRegistry = require("document/documentregistry")
local Koptinterface = require("document/koptinterface")
local util = require("ffi/util")
local DEBUG = require("dbg")
DEBUG:turnOn()
DEBUG("args", arg)
function logDuration(filename, pageno, dur)
local file = io.open(filename, "a+")
if file then
file:write(string.format("%s\t%s\n", pageno, dur))
file:close()
end
end
function doAutoBBox(doc, page)
Koptinterface:getAutoBBox(doc, page)
end
function doReflow(doc, page)
Koptinterface:getCachedContext(doc, page)
end
function benchmark(filename, doForOnePage)
local doc = DocumentRegistry:openDocument(filename)
for i = 1, doc:getPageCount() do
local secs, usecs = util.gettime()
doForOnePage(doc, i)
local nsecs, nusecs = util.gettime()
local dur = nsecs - secs + (nusecs - usecs) / 1000000
DEBUG("duration for page", i, dur)
logDuration("benchmark.txt", i, dur)
end
end
--benchmark(arg[1], doAutoBBox)
benchmark(arg[1], doReflow)