Updated by Anirvan Sarkar over 11 years ago
From r1474 AMC uses @savebox@ to save computing time when @shape=oval@. It will take even less time if @storebox@ is used instead of @savebox@.
Following test case result justifies this.
Create a file named *savebox.tex* with the code:
<pre>
\documentclass[a4paper]{article}
\usepackage{fancybox}
\usepackage{tikz}
\usepackage{forloop}
\newsavebox{\mybox}
\newcounter{counter}
\begin{document}
\savebox{\mybox}
{
\begin{tikzpicture}
\foreach \x in {1,1.001,1.002,...,2}
{
\draw (0+\x,0) circle (0.4cm);
}
\end{tikzpicture}
}
\forloop{counter}{0}{\value{counter} < 50}
{
\usebox{\mybox}\\
}
\end{document}
</pre>
This creates a @tikzpicture@ which is used for 50 times.
The output of the command @time pdflatex savebox.tex@ on my computer is:
<pre>
real 0m8.461s
user 0m8.384s
sys 0m0.060s
</pre>
Create another file named *storebox.tex* with the code:
<pre>
\documentclass[a4paper]{article}
\usepackage{storebox}
\usepackage{tikz}
\usepackage{forloop}
\newstorebox{\mybox}
\newcounter{counter}
\begin{document}
\storebox{\mybox}
{
\begin{tikzpicture}
\foreach \x in {1,1.001,1.002,...,2}
{
\draw (0+\x,0) circle (0.4cm);
}
\end{tikzpicture}
}
\forloop{counter}{0}{\value{counter} < 50}
{
\usestorebox{\mybox}\\
}
\end{document}
</pre>
Here we are using a @storebox@ instead of @savebox@.
The output of the command @time pdflatex storebox.tex@ on my computer is:
<pre>
real 0m2.498s
user 0m2.456s
sys 0m0.028s
</pre>
Conclusion: @storebox@ is *faster!!*
+Things to note:+
# As the number of times @savebox@ used is increased, the time taken to generate pdf file also increases. For example change the counter from 50 to 60,70,80,... You will notice that time also increases. If you keep on increasing the counter after sometime(counter set to 100) you may get the error: _! TeX capacity exceeded, sorry [main memory size=3000000]_. But with @storebox@ the time is almost constant. Even with counter set to *5000*, the time taken to generate the pdf file was only about *3.1 seconds*.
# As @storebox@ stores the box content as a reference instead of writing it every time to the output file (which @savebox@ does), the pdf file generated is also smaller.
The shift from @savebox@ to @storebox@ will take very less effort. One has to use the package @storebox@ instead of @fancybox@, use the command @\newstorebox@ instead of @\newsavebox@, @\storebox@ instead of @\savebox@ and @\usestorebox@ instead of @\usebox@.
Following test case result justifies this.
Create a file named *savebox.tex* with the code:
<pre>
\documentclass[a4paper]{article}
\usepackage{fancybox}
\usepackage{tikz}
\usepackage{forloop}
\newsavebox{\mybox}
\newcounter{counter}
\begin{document}
\savebox{\mybox}
{
\begin{tikzpicture}
\foreach \x in {1,1.001,1.002,...,2}
{
\draw (0+\x,0) circle (0.4cm);
}
\end{tikzpicture}
}
\forloop{counter}{0}{\value{counter} < 50}
{
\usebox{\mybox}\\
}
\end{document}
</pre>
This creates a @tikzpicture@ which is used for 50 times.
The output of the command @time pdflatex savebox.tex@ on my computer is:
<pre>
real 0m8.461s
user 0m8.384s
sys 0m0.060s
</pre>
Create another file named *storebox.tex* with the code:
<pre>
\documentclass[a4paper]{article}
\usepackage{storebox}
\usepackage{tikz}
\usepackage{forloop}
\newstorebox{\mybox}
\newcounter{counter}
\begin{document}
\storebox{\mybox}
{
\begin{tikzpicture}
\foreach \x in {1,1.001,1.002,...,2}
{
\draw (0+\x,0) circle (0.4cm);
}
\end{tikzpicture}
}
\forloop{counter}{0}{\value{counter} < 50}
{
\usestorebox{\mybox}\\
}
\end{document}
</pre>
Here we are using a @storebox@ instead of @savebox@.
The output of the command @time pdflatex storebox.tex@ on my computer is:
<pre>
real 0m2.498s
user 0m2.456s
sys 0m0.028s
</pre>
Conclusion: @storebox@ is *faster!!*
+Things to note:+
# As the number of times @savebox@ used is increased, the time taken to generate pdf file also increases. For example change the counter from 50 to 60,70,80,... You will notice that time also increases. If you keep on increasing the counter after sometime(counter set to 100) you may get the error: _! TeX capacity exceeded, sorry [main memory size=3000000]_. But with @storebox@ the time is almost constant. Even with counter set to *5000*, the time taken to generate the pdf file was only about *3.1 seconds*.
# As @storebox@ stores the box content as a reference instead of writing it every time to the output file (which @savebox@ does), the pdf file generated is also smaller.
The shift from @savebox@ to @storebox@ will take very less effort. One has to use the package @storebox@ instead of @fancybox@, use the command @\newstorebox@ instead of @\newsavebox@, @\storebox@ instead of @\savebox@ and @\usestorebox@ instead of @\usebox@.