From 9beebb965294dc7d9243d68eb6a4be0bf710c848 Mon Sep 17 00:00:00 2001 From: lvjr Date: Sun, 12 Jan 2025 12:50:34 +0800 Subject: [PATCH] add benchmark files --- .github/workflows/benchmark.yml | 32 ++++ .../workflows/{texlive.yml => regression.yml} | 2 +- .../{texlive.package => texlive-package.txt} | 0 .github/workflows/texlive.bat | 2 +- benchmark/benchmark.lua | 170 ++++++++++++++++++ benchmark/benchmark.tex | 58 ++++++ 6 files changed, 262 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/benchmark.yml rename .github/workflows/{texlive.yml => regression.yml} (98%) rename .github/workflows/{texlive.package => texlive-package.txt} (100%) create mode 100644 benchmark/benchmark.lua create mode 100644 benchmark/benchmark.tex diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 0000000..3c86a41 --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -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: codehigh + 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 diff --git a/.github/workflows/texlive.yml b/.github/workflows/regression.yml similarity index 98% rename from .github/workflows/texlive.yml rename to .github/workflows/regression.yml index a5e78c7..80a4914 100644 --- a/.github/workflows/texlive.yml +++ b/.github/workflows/regression.yml @@ -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: | diff --git a/.github/workflows/texlive.package b/.github/workflows/texlive-package.txt similarity index 100% rename from .github/workflows/texlive.package rename to .github/workflows/texlive-package.txt diff --git a/.github/workflows/texlive.bat b/.github/workflows/texlive.bat index 02ac197..febb288 100644 --- a/.github/workflows/texlive.bat +++ b/.github/workflows/texlive.bat @@ -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 diff --git a/benchmark/benchmark.lua b/benchmark/benchmark.lua new file mode 100644 index 0000000..5e7a322 --- /dev/null +++ b/benchmark/benchmark.lua @@ -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") diff --git a/benchmark/benchmark.tex b/benchmark/benchmark.tex new file mode 100644 index 0000000..05c0b78 --- /dev/null +++ b/benchmark/benchmark.tex @@ -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}