改进代码以减少编译时间

改进代码以减少编译时间

考虑以下 MWE:

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar,colormaps}
\pagecolor{black}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[
background rectangle/.style={
    inner color=violet!70!black,
    outer color=black
},
show background rectangle
]
  \begin{polaraxis}[
      domain  = -14400:14400,
      samples = 500,
      hide axis,
      colormap/violet
    ]
    \addplot[no markers,mesh,opacity=0.5] {sin(.5*x)};
    \addplot[no markers,mesh,opacity=0.5] {sin(.2*x)};
    \addplot[no markers,mesh,opacity=0.5] {sin(3*x)};
        \addplot[no markers,mesh,opacity=0.5] {1-sin(.5*x)};
        \addplot[no markers,mesh,opacity=0.5] {1-sin(.2*x)};
        \addplot[no markers,mesh,opacity=0.5] {1-sin(3*x)};
    \end{polaraxis}
  \node[below left=.1cm,white] at (current bounding box.north east) {\textcolor{violet}{I}nspiration};
%  \node[black] at (current bounding box.south) {
%   \begin{tabular}{rl}
%   \textit{by} & \\
%   & \textsc{MY NAME}
%   \end{tabular}
%  };
\end{tikzpicture}
\begin{tikzpicture}[
background rectangle/.style={
    inner color=orange!80!black,
    outer color=black
},
show background rectangle
]
\begin{polaraxis}[
domain  = -14400:14400,
samples = 5000,
hide axis
]

\addplot[no markers,mesh,opacity=.5] {1-sin(2*cos(x/(sin(x)+1))*x)};
\addplot[no markers,mesh,opacity=.5] {sin(2*cos(x/(sin(x)+1))*x)};

\end{polaraxis}
\node[below left=.1cm,white] at (current bounding box.north east) {\textcolor{orange}{C}reativity};
%\node[white] at (current bounding box.south) {
%   \begin{tabular}{rl}
%   \textit{by} & \\
%   & \textsc{MY NAME}
%   \end{tabular}
%};
\end{tikzpicture}
\begin{tikzpicture}[
background rectangle/.style={
    inner color=blue!30!black,
    outer color=black
},
show background rectangle
]
\begin{polaraxis}[
domain  = -14400:14400,
samples = 5000,
hide axis
]

\addplot[colormap/cool,no markers,mesh,opacity=.5] {x*sin(x)+x*cos(x/2)};
\end{polaraxis}
\node[below left=.1cm,white] at (current bounding box.north east) {\textcolor{blue}{C}reation};
%\node[black] at (current bounding box.south) {
%   \begin{tabular}{rl}
%   \textit{by} & \\
%   & \textsc{MY NAME}
%   \end{tabular}
%};
\end{tikzpicture}
\end{document}

输出如下:

截屏

我的问题是:如何简化/改进代码以使编译速度更快(当然这取决于计算机和机器,但我的意思是一般来说......)

答案1

假设已安装 gnuplot,您可以将所有 \addplot […] 替换为 \addplot […] gnuplot 并使用 shell-escape 进行编译。

在华硕 X205TA(非常便宜的机器)上编译 Debian

$ time pdflatex tex-ecm-Ia6t.tex # 你的 mwe
这是 pdfTeX,版本 3.14159265-2.6-1.40.19(TeX Live 2019/dev/Debian)(预加载格式=pdflatex)
限制 \write18 启用。

[剪辑]
实际 3m43,067s
用户 3m42,941s
系统 0m0,210s

$ time pdflatex -shell-escape tex-ecm-Ia6t.tex # 我的 mwe 与 gnuplot
这是 pdfTeX,版本 3.14159265-2.6-1.40.19(TeX Live 2019/dev/Debian)(预加载格式=pdflatex)
\write18 已启用。

[剪辑]
实际 2m4,887s
用户 2m4,431s
系统 0m0,466s

$ time pdflatex -shell-escape tex-ecm-Ia6t.tex #使用 \usetikzlibrary{external} \tikzexternalize

这是 pdfTeX,版本 3.14159265-2.6-1.40.19(TeX Live 2019/dev/Debian)(预加载格式=pdflatex)
\write18 已启用。

[剪辑]
实际 0m2,241s
用户 0m2,028s
系统 0m0,204s

相关内容