Skip to content

Commit

Permalink
add benchmark files
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjr committed Jan 12, 2025
1 parent 7dfba47 commit 699f73a
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 2 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Run benchmark tests in TeX Live

on: push

jobs:
run-ubuntu:
runs-on: ubuntu-latest
strategy:
matrix:
version: [2022, 2023, 2024]
steps:
- uses: actions/checkout@v4
- name: Install TeX Live
uses: teatimeguest/setup-texlive-action@v3
with:
version: ${{matrix.version}}
package-file: .github/workflows/texlive-package.txt
packages: ppmcheckpdf
update-all-packages: true
- name: Run benchmark tests for codehigh package
run: |
cd benchmark
texlua benchmark.lua ${{matrix.version}}
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
name: Codehigh Benchmark in TeX Live ${{matrix.version}}
tool: "customSmallerIsBetter"
output-file-path: benchmarks/output-${{matrix.version}}.txt
benchmark-data-dir-path: benchmark/${{matrix.version}}
github-token: ${{secrets.GITHUB_TOKEN}}
auto-push: true
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
tar -xzf install-tl-unx.tar.gz
cd install-tl-20*
./install-tl --profile ../.github/workflows/texlive.profile --repository=${{env.TLCurrent}}
echo $(cat ${{github.workspace}}/.github/workflows/texlive.package) | xargs tlmgr install
echo $(cat ${{github.workspace}}/.github/workflows/texlive-package.txt) | xargs tlmgr install
tlmgr update --self --all --no-auto-install --repository=${{env.TLCurrent}}
- name: Test codehigh with l3build
run: |
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion .github/workflows/texlive.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set pkgs=

:: the maximum length of the command line string is 8191 characters

for /f "tokens=*" %%A in (%~dp0texlive.package) do (
for /f "tokens=*" %%A in (%~dp0texlive-package.txt) do (
set /a j=j+1
rem echo !j!
set pkgs=!pkgs! %%A
Expand Down
170 changes: 170 additions & 0 deletions benchmark/benchmark.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
--- codehigh benchmark script

local function fileRead(input)
local f = io.open(input, "rb")
local text
if f then -- file exists and is readable
text = f:read("*all")
f:close()
return text
end
-- return nil if file doesn't exists or isn't readable
end

local function fileWrite(text, output)
-- using "wb" keeps unix eol characters
f = io.open(output, "wb")
f:write(text)
f:close()
end

local function fileNormalize(fname)
return string.gsub(fname, "/", "\\")
end

local function fileCopy(from, to)
if os.type == "windows" then
from = fileNormalize(from)
to = fileNormalize(to)
os.execute("copy /y" .. " " .. from .. " " .. to)
else
os.execute("cp -f" .. " " .. from .. " " .. to)
end
end

local function fileDelete(fname)
if os.type == "windows" then
fname = fileNormalize(fname)
os.execute("del" .. " " .. fname)
else
os.execute("rm" .. " " .. fname)
end
end

local warmupruns = 1
local benchruns = 4
local programs = {"pdflatex", "xelatex", "lualatex"}
local optn = "--interaction=nonstopmode"
local isquiet = true

local function makeCmdString(prog, name)
local str = prog .. " " .. optn .. " " .. name .. ".tex"
if isquiet == true then
if os.type == "windows" then
str = str .. " >NUL"
else
str = str .. " >/dev/null"
end
end
print(str)
return str
end

local function bmTestOne(tbl, prog, name)
for i = 1, warmupruns do
os.execute(makeCmdString(prog, name))
end
for i = 1, benchruns do
os.execute(makeCmdString(prog, name))
local text = fileRead(name .. ".log")
local t = string.match(text, "> \\g_benchmark_time_fp =([%d]+%.[%d]+)%.")
if t == nil then
error("failed to get benchmark time for " .. prog)
else
--print(prog .. " used time " .. i, t)
table.insert(tbl[prog], tonumber(t))
end
end
end

local function bmTestSome(tbl, name)
for _, p in ipairs(programs) do
bmTestOne(tbl, p, name)
end
end

local function initTimeTable(tbl)
for _, p in ipairs(programs) do
tbl[p] = {}
end
end

local oldtime = {}
local newtime = {}
local tblold = {}
local tblnew = {}
local tblratio = {}
local isoldfirst = true

local function bmRun(name)
initTimeTable(oldtime)
initTimeTable(newtime)
if isoldfirst then
fileDelete("codehigh.sty")
fileDelete("codehigh.lua")
bmTestSome(oldtime, name)
fileCopy("../codehigh.sty", "codehigh.sty")
fileCopy("../codehigh.lua", "codehigh.lua")
bmTestSome(newtime, name)
else
fileCopy("../codehigh.sty", "codehigh.sty")
fileCopy("../codehigh.lua", "codehigh.lua")
bmTestSome(newtime, name)
fileDelete("codehigh.sty")
fileDelete("codehigh.lua")
bmTestSome(oldtime, name)
end
for _, p in ipairs(programs) do
local oldt, newt = 0, 0
for i = 1, benchruns do
print(p .. " used time " .. i, "old = " .. oldtime[p][i], "new = " .. newtime[p][i])
oldt = oldt + oldtime[p][i]
newt = newt + newtime[p][i]
end
oldt = oldt / benchruns
newt = newt / benchruns
ratio = newt / oldt
print(p .. " average time " , "old = " .. oldt, "new = " .. newt, "ratio = " .. ratio)
tblold[p] = oldt
tblnew[p] = newt
tblratio[p] = ratio
end
end

local outtempl = [[{
"name": "compile codehigh with {{program}}",
"unit": "ratio",
"value": {{ratio}},
"extra": "current time : previous time = {{newtime}} : {{oldtime}}"
}]]

local function bmFillTemplate(prog, ratio, newt, oldt)
local str = outtempl
str = str:gsub("{{program}}", prog, 1)
:gsub("{{ratio}}", ratio, 1)
:gsub("{{newtime}}", newt, 1)
:gsub("{{oldtime}}", oldt, 1)
--print(str)
return str
end

local function bmOutput(tlver)
local out = {}
for _, p in ipairs(programs) do
table.insert(out, bmFillTemplate(p, tblratio[p], tblnew[p], tblold[p]))
end
local text = "[\n " .. table.concat(out, ",\n ") .. "\n]"
--print(text)
fileWrite(text, "output-" .. tlver .. ".txt")
end

local function main(name)
if arg[1] == nil then
error("missing texlive version")
else
bmRun(name)
bmOutput(arg[1])
end
end

main("tblrbenchmark")
58 changes: 58 additions & 0 deletions benchmark/benchmark.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
\documentclass{article}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{codehigh}
\usepackage{hyperref}
\usepackage{l3benchmark}
\ExplSyntaxOn
\int_set:Nn \l_iow_line_count_int {140} % default to 78
\let \replicate = \prg_replicate:nn
\AtBeginDocument{\benchmark_tic:}
\AtEndDocument{
\benchmark_toc:
\fp_log:n \g_benchmark_time_fp
}
\ExplSyntaxOff
\NewDocumentCommand\mylipsum{O{1}}{%
\replicate{#1}{The quick brown fox jumps over the lazy dog. }%
}
\begin{document}

\mylipsum[32]

\begin{codehigh}
% -*- coding: utf-8 -*-
\documentclass{article}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{codehigh}
\usepackage{hyperref}
\newcommand*{\myversion}{2021C}
\newcommand*{\mydate}{Version \myversion\ (\the\year-\mylpad\month-\mylpad\day)}
\newcommand*{\mylpad}[1]{\ifnum#1<10 0\the#1\else\the#1\fi}
\setlength{\abc}{1}
\begin{document}
% some comment
\section{Section Name}
\subsection*{Suction Name}
Math $a+b$.
\end{document}
\end{codehigh}

\mylipsum[32]

\begin{demohigh}[language=latex/table]
\begin{tabular}{lccr}
\hline
Alpha & Beta & Gamma & Delta \\
\hline
Epsilon & Zeta & Eta & Theta \\
\hline
Iota & Kappa & Lambda & Mu \\
\hline
\end{tabular}
\end{demohigh}

\mylipsum[32]

\dochighinput[language=latex/latex3]{codehigh.sty}

\end{document}

0 comments on commit 699f73a

Please sign in to comment.