I imagine that the bottleneck is in running the TikZ
code. However, to empirically check whether it is or not, a possible option would be to do make copies of the files that you're using and add:
function makefile(file)
f = io.open(file,"w")
f:write("\\documentclass{article}")
-- you could put the rest of your preamble here, or just copy paste it later
f:write("\\begin{document}")
end
and,
function closefile()
f:write("\\end{document}"}
f:close()
end
to the lua
portion. Then, make wrappers:
\def\start#1{\directlua{makefile("\luatexluaescapestring{#1}")}}
\def\stop{\directlua{closefile()}}
in the tex
preamble. You could then search/replace tex.print
with f:write
and run your file like:
\documentclass{article}
\usepackage{luacode}
\begin{luacode*} % or use a .lua file
function makefile(file)
f = io.open(file,"w")
f:write("\\documentclass{article}")
f:write("\\usepackage{...}")
f:write("\\begin{document}")
end
function closefile()
f:write("\\end{document}"}
f:close()
end
--your lua stuff here
\end{luacode*}
\def\start#1{\directlua{makefile("\luatexluaescapestring{#1}")}}
\def\stop{\directlua{closefile()}}
% your other preamble here
\begin{document}
\start{myfile.tex}
% your code
\stop{}
\end{document}
Some variation of the above should get you a compilable .tex
file. Running it will take the lua
stuff out of the equation. Thus, if it takes nearly an hour to compile you know that the bottleneck is on the TikZ side or at least get a feel for how much of the compilation time is actually taken up by running the code as opposed to producing it via lua
. If it turns out that the lua
is taking a significant portion of the compilation time, here are a couple of resources that might help you to speed it up:
http://www.lua.org/gems/sample.pdf
http://trac.caspring.org/wiki/LuaPerformance
and if you can confirm that TikZ takes too long, you should seriously consider the use of either TikZ's external library or the standalone package. Both can significantly speed-up the processing of documents with many tikz pictures (they are optimized for slightly different use-cases).
Best Answer
TeX engines are one-threaded, so they cannot distribute the load to multiple cores. TeX processing often require running external programs (biber, bibtex, makeindex), but since they need files produced by TeX and send their results to TeX as files, you cannot do much here either.
Still, there is an advantage of having a multicore machine: if your editor (or TeXStudio) runs on one core, and a TeX engine on another one, this will speed things up. However, this is usually automatically done by your OS, and is transparent to you.
Another situation is processing
rnw
documents withknitr
orSweave
. While R is also one-threaded, it can parallelize computations usingmulticore
package. This can speed R parts considerably.