Use storebox instead of savebox to save computing time (Feature #230)
Description
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:
\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}
This creates a tikzpicture which is used for 50 times.
The output of the command time pdflatex savebox.tex on my computer is:
real 0m8.461s user 0m8.384s sys 0m0.060s
Create another file named storebox.tex with the code:
\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}
Here we are using a storebox instead of savebox.
The output of the command time pdflatex storebox.tex on my computer is:
real 0m2.498s user 0m2.456s sys 0m0.028s
Conclusion: storebox is faster!!
Things to note:
- As the number of times
saveboxused 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 withstoreboxthe 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
storeboxstores the box content as a reference instead of writing it every time to the output file (whichsaveboxdoes), 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.
History
Updated by Alexis Bienvenüe over 12 years ago
storebox seems very good but I have a small issue with storebox: it inserts some space (see attached example). Thus calling \AMCboxDimensions will possibly break the layout, which can be annoying.
- File ab.pdf added
- File ab.tex added
Updated by Alexis Bienvenüe over 12 years ago
- File deleted (
ab.tex)
Updated by Alexis Bienvenüe over 12 years ago
- File deleted (
ab.pdf)
Updated by Alexis Bienvenüe over 12 years ago
(updated the example)
Updated by Alexis Bienvenüe over 11 years ago
Since hg:09d7e07592de, AMC uses storebox when package option storebox is set. However, \AMCboxStyle call can add some spaces and change the page layout, so it is recommended to use it once in a separate off-exam page, like
...
\begin{document}
Unused page.
\AMCboxStyle{shape=oval}
\clearpage
...
Updated by Alexis Bienvenüe over 5 years ago
- Status changed from New to Closed
- % Done changed from 0 to 100