125

I thought of that old joke today, where a programmer can make an undeniable excuse for his leisure activities while in work on the basis that he is just waiting for his code to compile.

Although I am a workaholic and a fair player, such an excuse comes in handy now and then, so what is the best way to achieve a long compilation time with as little additional code as possible?

Additional imaginary points shall be awarded for any cunning additional value such as making it hard for a LaTeX advanced user or even an expert to identify the cause straight away (the longer it takes, the better) or exceptionally creative ways of doing so.

All solutions must eventually compile, so indefinite loops and such are prohibited. The ideal solution should not produce written output to the built document, mask itself from the console output log, load as few packages as possible, and be difficult to detect.

Use this as a basic template and use e.g. UNIX time to find how long the compilation took (should any solutions come, I shall time them under the same conditions and post the results) (this is unnecessary since there are virtually infinite solutions).

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\title{Title}
\author{Author}
\date{Today}
\maketitle
\lipsum
\end{document}

Hopefully it is worth some time and a laugh and not just one of my idiomatic (and perhaps idiotic) creations.

  • 79
    Use any Java based TeX implementation – topskip Jul 2 '13 at 14:35
  • 5
    Now everyone of your colleagues knows that you are slacking off. And the boss too. – Sam Jul 2 '13 at 22:42
  • 27
    @topskip: [knock knock] - Who's there? [very long pause] - Java. :) – Paulo Cereda Jul 3 '13 at 1:06
  • 15
    Seriously? pdflatex thesis.tex 326.88s user 0.94s system 99% cpu 5:28.49 total That's 11 minutes every time I build that document. I pretty much already watched all of Youtube so this is not funny! – Christian Jul 3 '13 at 4:04
  • 4
    @karlkoeller What if I were the boss? ;-) Anyway, I am actually a workaholic and this is merely a joke, although undoubtedly sometimes useful. I shall continue sharing this great site and passion for LaTeX with my acquaintances. :-) – Harold Cavendish Jul 4 '13 at 14:08

19 Answers 19

69
+50

With pdfTeX, add

\everypar{\ifnum\pdfelapsedtime<\maxdimen
  \the\expandafter\everypar\else\pdfresettimer\fi}

(after the \begin{document} if you are using pdfLaTeX). This will wait four hours and a half (\maxdimen scaled seconds, that is, 2^{30-16} seconds) before starting each paragraph. Replace \maxdimen by 65536 (and a space) to get a one second delay at each paragraph. Compiling a book with, say, 1000 paragraphs takes about six months. Not bad for a 90 characters addition.

With a bit more code (184 characters), an engine-agnostic implementation of the Ackermann function lets us get pretty much any delay by changing the arguments of \A just a little bit (I am not sure at what point TeX's limits are exceeded). With

\def\A#1#2{\the\numexpr\B{#1}{#2+1}\empty
  {\A{#1-1}{\B{#2}1\empty{\A{#1}{#2-1}}.}}.\relax}
\def\B#1{\ifnum\numexpr#1=0 \C\else\C\fi}
\def\C#1#2#3#4#5.{#1#3#4}
\everypar{{\count0=\A{3}{1}}}

I add about 6 minutes per paragraph to the compilation time on my machine. An additional benefit of this answer is that the definitions can easily be scattered in the preamble to avoid detection. Using xint lets us manipulate larger numbers, hence give larger arguments to \A:

\usepackage{xint}
\def\C#1#2#3#4#5.{#1#3#4}
\def\b#1{\if0\s{#1}\C\else\C\fi}
\let\s\xintSgn
\let\d\romannumeral
\let\x\xintAdd
\def\a#1#2{\b{#1}{\x{#2}1}\empty{%
    \a{\x{#1}{-1}}
    {\d-`-\b{#2}1\empty{\a{#1}{\d-`-\x{#2}{-1}}}.}}.}
\everypar{\d-\xintSgn{\A{3}{1}} }

This last code is not tested: xint puts an overhead on TeX's arithmetic, which makes the whole thing way too slow. Slower, even, would be to use the bigintcalc package, which predates xint and is not as optimized.

  • 4
    I should add that this answer is inspired by David's answer, but does not produce any spurious output. – Bruno Le Floch Jul 4 '13 at 7:28
  • 1
    I think this is the only answer so far that matches the OPs intend: Not to produce some fancy, computational intensive output, but to really just burn CPU cycles. The code is also small enough to be hidden somehwere. It might be a good idea to obfuscate it somewhat more, though (elapsedtime and resettimer are still a bit too obvious). – Daniel Jul 4 '13 at 9:28
  • 4
    @Daniel Just to obfuscate it completely, create a "fake" copy of article.cls, and insert this code in a AtBeginDocument command: \AtBeginDocument{\everypar{\ifnum\pdfelapsedtime<\maxdimen\the\expandafter\everypar\else\pdfresettimer\fi}} – karlkoeller Jul 4 '13 at 13:13
  • 1
    @karlkoeller I know exactly how I am going to fool a friend of mine when I get an access to his machine! ^_^ – Harold Cavendish Jul 4 '13 at 18:44
  • 1
    @BrunoLeFloch I surely will! Originally, I intended to let him out of the misery after a couple of minutes but I like your idea of a more subtle but indeed longer execution. It has been an honour conspiring with you! :-D (And you will get the bounty as well since awarding the second best answer with 50 more points would be illogical.) – Harold Cavendish Jul 6 '13 at 0:13
42

This should keep you busy for a minute or two (I stopped my test run after 5 minutes)

\documentclass{article}


\begin{document}
\everypar{\ifnum\thepage000<\maxdimen\par\fi}

hello

\end{document}
  • 5
    Just out of curiosity, what does it do? – Jeel Shah Jul 2 '13 at 19:41
  • 19
    @gekkostate Open a Word document, write hello and press Home. Then put an ashtray on the Enter button, come back a week later... – percusse Jul 2 '13 at 20:37
  • Edited (added 000) so it doesn't run out of pdf objects and stops in reasonable time (just over 7 minutes on my machine) – David Carlisle Jul 2 '13 at 20:58
  • 2
    @gekkostate it makes some blank paragraphs then prints hello – David Carlisle Jul 2 '13 at 20:58
  • 1
    "Ooops, your LaTeX code couldn't compile for some reason. Please check these errors for details:" +1. – user32552 Jul 4 '13 at 9:10
32

Disclaimer: I'm not responsible for any damage this may cause to your CPU! :D

A solution based on hyperref and foreach:

\documentclass{article}
\usepackage{tikz}
\usepackage{hyperref}
\usepackage{lipsum}

\begin{document}
\title{The art of wasting time} 
\author{dcmst}
\maketitle
\lipsum[1]
  \begin{tikzpicture}
  \def \n {1000}
  \foreach \s in {1,...,\n}{
  \node {\hypertarget{\s}{}};
  \node {\hyperlink{\s}{}};
  }
  \end{tikzpicture}
\lipsum[1]
\end{document}

On a i7 laptop a loop of 1000 compiles in 3-4 seconds; a loop of 10000 in 53 seconds! Etc.

Just increase the number and you'll have more time to play with [insert you favorite video game here].

This does not produce any output at all, so you can also blame your old machine and ask for a newer, faster, one :)

Edit: looks like that 16383 is the maximum accepted value for \n. Then you can obviously stack more than one loop adding as many foreach as you need. Two foreach istances with a value of 10000 got me a TeX capacity exceeded error.

Edit.2: to remove compilation warnings a ~ or \null character can be added into the hypertarget and link second argument.

Edit.3: after increasing the main_memory amount I managed to keep the compilation going for 4 minutes before stopping manually. Instead of adding another foreach the time can be prolonged adding more couples of nodes like the two in the MWE.

  • 6
    What?! All my files are deleted! Just joking, +1. – user32552 Jul 4 '13 at 9:05
27

Draw a complicated diagram.

Include it several times in the document and don't optimise it. This one takes about 10s on my computer. Increasing the 89.9 in the first \foreach would mean it took even longer (though 89.99 produces an overflow). Drawing the same diagram several times would again increase the time it took.

\documentclass{article}
\thispagestyle{empty}
%\def\pgfsysdriver{pgfsys-tex4ht.def}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% \x runs over the angles at which to draw the circles defining the
% torus
\foreach \x in {90,89.9,...,-90} { % change 89 to 80 or 45 for speed
% \elrad is the x-radius of the ellipse (technically, a circle seen
% from side on at angle \x).  The 'max' is because at small angles
% then the real ellipse is too thin and the torus doesn't ``fill
% out'' nicely.
\pgfmathsetmacro\elrad{20*max(cos(\x),.1)}
% We draw the torus from the back to the front to get the right
% layering effect.  To tint it, we define colours according to the
% angle, but need different colours for the left and right pieces.
% It'd be nice if the xcolor colour specification could take something
% computed by pdfmath, such as {red!\tint} but it doesn't appear to
% work, so we define the colours explicitly.
\pgfmathsetmacro\ltint{.9*abs(\x-45)/180}
\pgfmathsetmacro\rtint{.9*(1-abs(\x+45)/180)}
\definecolor{currentcolor}{rgb}{\ltint, 0, \ltint}
% This draws the right-hand circle.
\draw[color=currentcolor,fill=currentcolor] (xyz polar cs:angle=\x,y radius=.75,x radius=1.5) ellipse (\elrad pt and 20pt);
% This sets the colour correctly for the left-hand circle ...
\definecolor{currentcolor}{rgb}{\rtint, 0, \rtint}
% ... and draws it
\draw[color=currentcolor,fill=currentcolor] (xyz polar cs:angle=180-\x,radius=.75,x radius=1.5) ellipse (\elrad pt and 20pt);
% End of foreach statement
}
% Spheres are *much* easier!
\shadedraw[shading=ball,ball color=purple, white] (6.5,0) circle (1.5);
% As are the subsets of Euclidean space
\draw[fill=cyan] (-1,-4) rectangle (1,-3);
\draw[fill=cyan] (5.5,-4) rectangle (7.5,-3);
% The next three draw the maps, slightly curved for aesthetics.
\draw[->] (0,-2.8) .. controls (-.2,-2.2) .. (0,-1.6) node[pos=0.5, auto=left] {\(\psi\)};
\draw[->] (6.5,-1.6) .. controls (6.7,-2.2) .. (6.5,-2.8) node[pos=0.5, auto=left] {\(\phi^{-1}\)};
\draw[->] (2.5,0) .. controls (3.5,.2) .. (4.5,0) node[pos=0.5, auto=left] {\(f\)};
% Now we want to draw the codomains of the charts.  Sticking cosines
% and sines directly into the coordinates doesn't seem to work so
% we define macros to hold the sines and cosines of the angles.
% \elrad is the angle on the torus at which to start.
\pgfmathsetmacro\elrad{cos(-135)}
% the circle drawn at the specific angle on the torus looks like an
% ellipse, \xrad and \yrad compute its major and minor semi-axes.
\pgfmathsetmacro\xrad{1.5cm-20pt*\elrad}
\pgfmathsetmacro\yrad{.75cm-20pt*sin(-135)}
% This draws the codomain of the chart on the torus.
\path[fill=cyan, fill opacity=.35] (xyz polar cs:angle=-135,radius=.75,x radius=1.5) ++(20pt*\elrad,0) arc (0:45:20*\elrad pt and 20pt) arc (-135:-45:\xrad pt and \yrad pt) arc (45:-45:-20*\elrad pt and 20pt) arc (-45:-135:\xrad pt and \yrad pt) arc (-45:0:20*\elrad pt and 20pt);
% Now we do the same for the sphere.
% We do this by drawing some great circles (aka ellipses) on the
% sphere and then ``clipping'' an overlaid (and slightly trans:parent)
% sphere by those great circles.  Each great circle actually specifies
% one side of the ``clip'' so to make sure that the clip is big enough
% the arcs are completed by big rectangles (otherwise the clipping
% would join the end points directly).
\pgfmathsetmacro\tell{-sin(10)}
\pgfmathsetmacro\bell{sin(50)}
\pgfmathsetmacro\rell{1.5 * sin(50)}
\begin{scope}
\clip (6.5,0) +(-1.5,0) arc (-180:0:1.5 and 1.5*\tell) -- ++(0,-1.5) -- ++(-3,0) -- ++(0,1.5);
\clip (6.5,0) +(-1.5,0) arc (-180:0:1.5 and 1.5*\bell) -- ++(0,1.5) -- ++(-3,0) -- ++(0,-1.5);
\clip (6.5,0) +(0,1.5)  arc (90:-90:\rell cm and 1.5 cm) -- ++(-1.5,0) -- ++(0,3) -- ++(1.5,0);
\clip (6.5,0) +(0,1.5)  arc (90:-90:-\rell cm and 1.5 cm) -- ++(1.5,0) -- ++(0,3) -- ++(-1.5,0);
\fill[cyan, fill opacity=0.35] (6.5,0) circle (1.5);
\end{scope}
\end{tikzpicture}
\end{document}

Result:

PDF Torus

Remarks:

  1. This is a diagram from a conference talk that I gave so it is not an example that I cooked up to answer this question.
  2. It is the torus that takes so long, it is drawn as a family of circles.
  3. When writing the seminar, I actually increased the step size considerably as it was taking so long to compile on each run, only decreasing it for the final compilation.
  4. When I gave this talk a second time, I found a quicker way of drawing the torus.
  • 1
    Not that toruses aren't impressive, but this answer doesn't seem to meet the 'stealth' criteria given in the question... – Alan Munn Jul 2 '13 at 19:15
  • 2
    @AlanMunn Change the line \definecolor{currentcolour}{...} to \definecolor{currentcolour}{1,1,1}. Seriously, the stealth part is the number of circles drawn. I defy you to tell the difference between 89 and 89.9 but the difference in time is huge. – Loop Space Jul 2 '13 at 19:31
  • @Andrew - On the off chance you were not already doing this, I believe putting the figure into an external .tex file allows the result of pgf and tkiz to be cached – Hamy Jul 3 '13 at 2:43
  • 1
    @Hamy I tend to use the extetnal library to achieve the same end. – Loop Space Jul 3 '13 at 6:09
  • 1
    @dimension10 Note that I said that my machine took 10s to compile it, so ShareLaTeX is taking 3 times longer (I'll take your word for that as SL requires a sign-up; WriteLaTeX gave me a "Compile Timeout"). But I also said that you should use the picture several times in the document, say in a beamer presentation with the picture drawn on a slide with lots of overlays. Or make it the logo so that it is drawn on every slide. – Loop Space Jul 4 '13 at 9:37
18

Keep an entire lecture series of beamer presentations in a single file.

As in my other answer, this piece of advice comes from a real world situation. Of course, normally one is trying to reduce the compilation time and it was in search of this aim that I developed the tools that I mention in https://tex.stackexchange.com/a/52904/86. But if you don't use such methods, compiling a lecture from a beamer file that contains an entire course of lectures can take ... time.

(For hopefully obvious reasons I'm not going to post code for this one!)

  • ha ha, I enjoy that you've now posted multiple "solutions" to the raw question of 'how do you make tex compilation slow' – Hamy Jul 3 '13 at 2:44
  • 2
    This methods becomes a lot more effective in combination with TikZ images that use remember picture, overlay – not to say \tikzmark – in every frame. – Daniel Jul 4 '13 at 9:30
16

Install an antivirus software and make it check thoroughly all the files of your TeX installation. No extra coding required, but the effect varies with the amount of packages and fonts you load.

(That's why my Windows colleagues have much more leisure time than I do...)

16

This is perhaps a simplified pstricks-version of Andrew's answer.

Of the 25 frames, the first compiles & renders in under a second. The last compiles quickly, but the Postscript rendering takes roughly 3 minutes with the only difference being the specification of the ngrid key:

enter image description here

The beauty about the code that produces this is all contained in a single macro \psSolid. For super-smooth, lengthy leisure, ngrid=180 360 compiles in about 40 minutes:

enter image description here

\documentclass[pstricks,border=0pt]{standalone}
\usepackage{pst-solides3d}% http://ctan.org/pkg/pst-solides3d
\usepackage{multido}% http://ctan.org/pkg/multido
\pagestyle{empty}
\begin{document}
\begin{pspicture}(-3,-2)(3,2)
  \psset{viewpoint=50 50 30 rtp2xyz,Decran=25,lightsrc=viewpoint}
  \psSolid[r1=3.5,r0=1,
    object=tore,
    linewidth=0pt,
    ngrid=180 360,
    fillcolor=magenta!30,
    action=draw**]%
  \axesIIID(4.5,4.5,0)(5,5,4)
\end{pspicture}
\end{document}

A "spy" of some of the ~65K polygonal constructions, which is worth the wait (if needed):

enter image description here

En garde!

  • 3
    and run the documents with xelatex ... – user2478 Jul 3 '13 at 8:04
14

There is a reason I wrote the titlecaps package... The \capitalizetitle command of the stringstrings package was an embarassment. What titlecaps can do in a second or two, this stringstrings routine takes upwards of two minutes on my machine. Passing an optional [v] argument to \testcompiler will print out the result, which I did not do at the request of the questioner.

\documentclass{article}
\usepackage{stringstrings}
\newcommand\testcompiler[1][q]{%
  \addlcwords{as the for to and on a in not from by}
  \capitalizetitle[#1]{four score and seven years ago our fathers
  brought forth on this continent a new nation, conceived in liberty,
  and dedicated to the proposition that all men are created equal.}%
}
\begin{document}
\testcompiler
\end{document}
14

This might be a ConTeXt-only option.

You can try referencing fonts by their names, without telling TeX that the name you're using is not a filename. This was another real-world situation. As described in this question: ConTeXt keeps trying to create "missing" font files, I was getting a 40x to 60x slowdown using this technique!

E.g.

\definefont[SerifS][GentiumBookBasic at \smallfontsize]
13

Option 1: Randomly-Viewed Sliced Image

Based on HV's answer. By changing \N to 30 or more, you will have longer time to wait.

\documentclass[pstricks]{standalone}
\usepackage{multido}
\usepackage{graphicx}
\usepackage{fp}
\SpecialCoor

\FPset\N{10}% 30 or more provides you with longer time to wait
\FPeval\MaxElements{N*N}

\newsavebox\IBox
\savebox\IBox{\includegraphics{example-image}}
\psset
{
    xunit=\dimexpr\wd\IBox/\N,
    yunit=\dimexpr\ht\IBox/\N,
}

\def\txG{ true setglobal globaldict begin }
\def\etxG{ end false setglobal }

\pstVerb{\txG
    /u.n \N\space \N\space mul def
    /Elements [ 0 1 u.n 1 sub { } for ] def
    realtime srand
    /GetElement { 
        rand u.n mod /Random ED
        Random 
        Elements length mod Elements exch get dup
        \N\space mod /u.Col ED % col
        \N\space div cvi /u.Row ED % row
        Elements aload length dup 1 sub /u.n ED 
        Random sub -1 roll pop u.n array astore /Elements ED
    } def
    \etxG }


\begin{document}
\foreach \x in {1,2,...,\MaxElements}{%
\begin{pspicture}(\N,\N)
\rput[lb](0,0){%
    \psclip{\psframe[linestyle=none,linewidth=0](! \txG GetElement u.Row u.Col \etxG)(! \txG u.Row 1 add u.Col 1 add \etxG)}
        \usebox\IBox
    \endpsclip}
\end{pspicture}}
\end{document}

enter image description here

In addition to the long compilation, you also needs longer time to reveal the sliced output. The image above, as an example, was taken from this site.

To avoid wasting your internet bandwidth, I hide the image of 30 by 30 grid here.

Option 2: Fractal

Changing the size to 10cm by 10cm or more provides you with a longer time to wait.

\documentclass[border=12pt]{standalone}
\usepackage{pst-fractal}

\begin{document}
\psfractal
[
    type=Mandel,
    baseColor=red,
    maxRadius=30,
    dIter=30,
    cx=-1.3,
    xWidth=10cm,% change to a longer value to take more time to compile
    yWidth=10cm,% change to a longer value to take more time to compile
](-3,-2)(2,2)
\end{document}

enter image description here

  • 1
    Implementing BOGO sort with an extremely huge number of elements is my zeroth option. – kiss my armpit Jul 3 '13 at 17:14
8

Let LaTeX play Towers of Hanoi. The code below seems to do the job, I have deleted the parts which I think are responsible for actually drawing the towers in the linked example (which contradicts the requirements), but tikz is still required for this code:

% The logic for Hanoi, we record the discs at every pole
% as a comma separated list ending with a '.'; i.e. the
% starting list for 4 discs would be 1,2,3,4,.
\newcount\ndiscs
\def\initpoles#1{
    \def\disclist{}
    \foreach \n in {1,...,#1} {
        \xdef\disclist{\disclist\n,}
    }
    \expandafter\xdef\csname pole 1\endcsname{\disclist.}
    \expandafter\gdef\csname pole 2\endcsname{.}
    \expandafter\gdef\csname pole 3\endcsname{.}
}

% Delimited macro; #1 is everything up to the first ',' and
% #2 everything after it.
\def\head#1,#2.{#1}
\def\tail#1,#2.{#2}

% This macro updates the disc lists, its arguments are the name
% names of the macro's corresponding to the poles, for example
% 'pole 1' and 'pole 3'.
\def\movedisc#1#2{
      \edef\lista{\csname #1\endcsname}
      \edef\listb{\csname #2\endcsname}
      \expandafter\xdef\csname #2\endcsname{\expandafter\head\lista,\listb}
      \expandafter\xdef\csname #1\endcsname{\expandafter\tail\lista.}
}

% Updates the lists and then draws a new frame.
\def\move#1#2{
      \movedisc{pole #1}{pole #2}
}

% This macro boils down to a well-known recursive solution, as given
% here for example: http://en.wikipedia.org/wiki/Towers_of_Hanoi#Recursive_solution
%
% #1 Pole to move from
% #2 Pole to move to
% #3 Pole to use as scratch
% #4 Number of disks
\def\rhanoi#1#2#3#4{
      \ifnum#4>1
          {\advance#4 by -1 \rhanoi#1#3#2#4}
          \move{#1}{#3}
          {\advance#4 by -1 \rhanoi#2#1#3#4}
      \else
          \move{#1}{#3}
      \fi
}

% Main macro, inits the lists for the current number, sets a title
% for the frame and starts the recursion.
\def\hanoi#1{
        \ndiscs=#1
        \initpoles{#1}
        % Recursion draws a new frame for every step.
        \rhanoi{1}{2}{3}{\ndiscs}
}

Call it with

\hanoi{20}

or something like this -- this keeps my machine busy for 13 seconds, and each increase roughly doubles the run time. The code is also on GitHub.

Not very well hidden, though... Unless you manage to push a package to CTAN that contains this code. EDIT: Unfortunately, the hanoi package is limited to 15 discs, so it's not useful for our purpose.

6

Run LaTeX on a 10-year-old computer with a slow processor. Make sure that before you compile, you have lots of applications already open, filling up the RAM, so that the OS will have to do a lot of swapping with the pagefile in order to run LaTeX on your document. For added measure, make sure that your hard drive is almost full, and severely fragmented.

This comes from a real-world situation for me!

  • 6
    Using a dynamically growing page file on the main system partition was probably the third most stupid decision Microsoft made for Windows after rejecting network passwords as soon as receiving the first wrong character and allowing random people to write popup messages on your screen. – Christian Jul 3 '13 at 3:45
  • 2
    And replace the RAM by a smaller size. – kiss my armpit Jul 3 '13 at 17:01
5

You could come up with some TikZ code to graph some fancy curves. Using trigonometric functions and foreach loops profusely will do the trick, and the code doesn't even have to be very long (or complicated). For example see:

If that's still not enough, use reference-in-references (this one will require at least: pdfLaTeX -> Biber -> PDFLaTeX -> Biber -> PDFLaTeX -> PDFLaTeX) to make sure the number of compilations is as high as possible. Glossaries and lists of symbols help also, preferably generated with different packages to eliminate the possibility of having them done in one pass (all right, this might not really meet the criterion of 'loading as few packages as possible').

5

This is not an answer but a too long comment on Bruno's computation of the Ackermann function. Here is an implementation which computes in reasonable time up to A(3,8) (and A(4,0) which is instantaneous but not A(4,1), which is worse than A(3,8)). However A(3,9) ends up in:

ERROR: TeX capacity exceeded, sorry [expansion depth=10000].

Thus the problem here is that the implementation is too fast to be relevant to the OP, and then it falls into oblivion due to this defect of too deep expansion nesting.

update (2017): but naturally one can compute A(4,2) directly by using explicit formula: 2^(2^(2^(2^2)))-3. This takes some time...

$ rlwrap etex -jobname acker42
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017) (preloaded format=etex)
 restricted \write18 enabled.
**xintexpr.sty
entering extended mode
(/usr/local/texlive/2017/texmf-dist/tex/generic/xint/xintexpr.sty
(/usr/local/texlive/2017/texmf-dist/tex/generic/xint/xintfrac.sty
(/usr/local/texlive/2017/texmf-dist/tex/generic/xint/xint.sty
(/usr/local/texlive/2017/texmf-dist/tex/generic/xint/xintcore.sty
(/usr/local/texlive/2017/texmf-dist/tex/generic/xint/xintkernel.sty))))
(/usr/local/texlive/2017/texmf-dist/tex/generic/xint/xinttools.sty))
*\message{\xinttheiiexpr 2^(2^(2^2))-3\relax}
65533
*\message{\xinttheiiexpr 2^(2^(2^(2^2)))-3\relax}

2003529930406846464979072351560255750447825475569751419265016973710894059556311
4530895061308809333481010382343429072631818229493821188126688695063647615470291
6504187191635158796634721944293092798208430910485599057015931895963952486337236
7203002916969592156108764948889254090805911457037675208500206671563702366126359
7471448071117748158809141357427209671901518362825606180914588526998261414250301
2339110827360384376787644904320596037912449090570756031403507616256247603186379
3126484703743782954975613770981604614413308692118102485959152380195331030292162
8001605686701056516467505680387415294638422448452925373614425336143737290883037
9460127472495841486491593064725201515569392262818069165079638106413227530726714
3998158508811292628901134237782705567421080070065283963322155077831214288551675
5540733451072131124273995629827197691500548839052238043570458481979563931578535
1001899200002414196370681355984046403947219401606951769015611972698233789001764
1517190051133466306898140219383481435426387306539552969691388024158161859561100
6403621197961018595348027871672001226046424923851113934004643516238675670787452
5946467090388654774348321789701276445552940909202195958575162297333357615955239
4885297579954028471943529913543763705986928913757153740001986394332464890052543
1066296691652434191746913896324765602894151997754777031380647813423095961909606
5459130089018888758808473362595606544488850144733570605881709016210849971452956
8344061979690565469813631162053579369791403236328496233046421066136200220175787
8518574091620504897117818204001872829399434461862243280098373237649318147898481
1945271300744022076568091037620399920349202390662626449190916798546151577883906
0397720759279378852241294301017458086862263369284725851403039615558564330385450
6886522131148136384083847782637904596071868767285097634712719888906804782432303
9471865052566097815072986114143030581692792497140916105941718535227588750447759
2218301158780701975535722241400019548102005661773589781499532325208589753463547
0077866904064290167638081617405504051176700936732028045493390279924918673065399
3164072049223847481528061916690093380573212081635070763435166986962502096902316
2859350071874190579161241536897514808261904847946571736601005892476655445840838
3347905441448176842553272073155863493476051374197795251903650321980201087647383
6868253102518337753390886142618480037400808223810407646887847164755294532694766
1700424461063311238021134588694532200116564076327023074292426051582811070387018
3453245676356259514300320374327407808790562836634069650308442258559670392718694
6115851379338647569974856867007982396060439347885086164926030494506174341236582
8352144806726676841807083754862211408236579802961200027441324438432402331257403
5450193524287764308802328508558860899627744581646808578751158070147437638679769
5504999164399828435729041537814343884730348426190338884149403136613985425763557
7105335580206622185577060082551288893332226436281984838613239570676191409638533
8323743437588308592337222846442879962456054769324289984326526773783731732880632
1075321123868060467470842805116648870908477029120816110491255559832236624486855
6651402684641209694982590565519216188104341226838996283071654868525536914850299
5396755039549383718534059000961874894739928804324963731657538036735867101757839
9481847179849824694806053208199606618343401247609663951977802144119975254670408
0608499344178256285092726523709898651539462193004607364507926212975917698293892
3670151709920915315678144397912484757062378046000099182933213068805700465914583
8720808801688744583555792625846512476308714856631352893416611749061752667149267
2176128330845273936469244582892571388877839056300482483799839692029222215486145
9023734782226825216399574408017271441461795592261750838890200741699262383002822
8624928418267124340575142418856999427233160699871298688277182061721445314257494
4015066139463169197629181506579745526236191224848063890033669074365989226349564
1146655030629659601997206362026035219177767406687774635493753188995878662821254
6979710206574723272137291814466665942187200347450894283091153518927111428710837
6159222380276605327823351661555149369375778466670145717971901227117812780450240
0263847587883393968179629506907988171216906869295382485298300234760684541141781
3911064856023654975422749723100761513187002405391051091381784372179142252858743
2098524957878034683703337818421444017138688124249984418618129271198533315382567
3218704215306311977485352146709553346263366108646673322924098798492566911095161
4361860154890974024191350962304361219612816595051866602203071561368473236466086
8905014263913906515063908199378852318365059897299125404479443425166774299659811
8492331515552728832740283526884424087528112832899806259126736995462473415433335
0014723143061275039030739713525206933817384332295070104906186753943313078479801
5655130384758155685236218010419650255596181934986315913233036096461905990236112
6811960234418433633345949276319461017166529138237171823942992162725384617760656
9454229787707138319881703696458868981186321097690035573588462446483570629145305
2757101278872027965364479724025405448132748391794128826423835171949197209797145
9368875371987291308317380339110161285474153773777159517280841116275971863849242
2280237344192546999198367219213128703558530796694271341639103388275431861364349
0100943197409047331014476299861725424423355612237435715825933382804986243892498
2227807159517627578471094751190334822414120251826887137281931042534781961284401
7647953150505711072297431456991522345164312184865757578652819756484350895838472
2923534559464521215831657751471298708225909292655638836651120681943836904116252
6687100445602437042006637090019411855571604720446436969328500600469281405071190
6926139399390273553454556747031490388602202463994826050176243196930564066636662
6090207048887438898907498152865444381862917382901051820869936382661868303915273
2645812867828066013375000965933646251460917231803129303478774212346791184547913
1110989779464821692250562939995679348380169915743970053754213448587458685604728
6751065423341893839099110586465595113646061055156838541217459801807133163612573
0796111683438637676673073545834947897883163301292408008363568259391571131309780
3051644171668251834657367593419808495894794098329250008638977856349469321247342
6103062713745077286156922596628573857905533240641849018451328284632709269753830
8673084091422476594744399733481308109863994173797896570106870267341619671965915
9958853783482298827012560584236558953969030647496558414798131099715754204325639
5776070485100881578291408250777738559790129129407309462785944505859412273194812
7532251523248015034665190482289614066468903051025109162377704484862302294889667
1138055560795662073244937337402783676730020301161522700892184351565212137921574
8206859356920790214502277133099987729459596952817044582181956080965811702798062
6698912050615607423256868422713062950098644218534708104071289176469065508361299
1669477802382250278966784348919940965736170458678624255400694251669397929262471
4524945408858422726153755260071904336329196375777502176005195800693847635789586
8784895368721228985578068265181927036320994801558744555751753127364714212955364
9408438558661520801211507907506855334448925869328385965301327204697069457154695
9353658571788894862333292465202735853188533370948455403336565356988172582528918
0566354883637437933484118455801683318276768346462919956055134700391478768086403
2262961664156066750815371064672310846196424753749055374480531822600271021640098
0584497526023035640038083472053149941172965736785066421400842696497103241919182
1212132069397691439233683747092282677387081322366800869247034915868409911530983
1541206356612318750430546753698323082796645741762080659317726568584168183796610
6144963432544111706941700222657817358351259821080769101961052229263879745049019
2543119006205619065774524161919131875339840493439768233102984658933183730158095
9252282920682086223033258528011926649631444131644277300323779227471233069641714
9945532261035475145631290668854345426869788447742981777493710117614651624183616
6802548152963353084908499430067636548061029400946937506098455885580439704859144
4958444507997849704558355068540874516331646411808312307970438984919050658758642
5810738422420591191941674182490452700288263983057950057341711487031187142834184
4991534567029152801044851451760553069714417613685823841027876593246626899784183
1962031226242117739147720800488357833356920453393595325456489702855858973550575
1235129536540502842081022785248776603574246366673148680279486052445782673626230
8529782650571146248465959142102781227889414481639949738818846227682448516220518
1707672216986326570165431691974265123004175732990447353767253684579275436541282
6553581858046840069367718605020070547247548400805530424951854495267247261347318
1747421800785746934654471360369758841180294080396167469462885406791721386012254
1950381970453841726800639882065632879283958270851091995883944829777564715202613
2871089526163417707151642899487953564854553553148754978134009964854498635824847
6905900331169613037661279234643231297066284113074270462020320133683503854253603
1363676357521260470742531120923340283748294945310472741896928727557202761527226
8283376741393425652653283068469997597097750005560889932685025049212884068274139
8816315404564903507758716800740556857240217586854390532281337707074158307562696
2831695568742406052772648585305061135638485196591896864959633556821697543762143
0778665934730450164822432964891270709898076676625671517269062058815549666382573
8292741820822789606844882229833948166709840390242835143068137672534601260072692
6296946867275079434619043999661897961192875051944235640264430327173734159128149
6056168353988188569484045342311424613559925272330064881627466723523751234311893
4421188850850793581638489944875447563316892138696755743027379537852625423290248
8104718193903722066689470220425883689584093999845356094886994683385257967516188
2159410981624918741813364726965123980677561947912557957446471427868624053750576
1042042671493660849802382746805759825913310069199419046519065311719089260779491
1921794640735512963386452303567334558803331319708036545718479155043265489955970
5862888286866606618021882248602144999973122164138170653480175510438406624412822
8036166489042573776409563264828252584076690456084394903252905263375323165090876
8133661424239830953080654966187938194912003391948949406513239881664208008839555
4942237096734840072642705701165089075196155370186264797456381187856175457113400
4738107627630149533097351741806554791126609380343113785325328835333520249343659
7912934128485497094682632907583019307266533778255931433111096384805394085928398
8907796210479847919686876539987477095912788727475874439806779824968278272200926
4499445593804146087706419418104407582698056880389496546165879839046605876453418
1028990719429302177451997610449504319684150345551404482092893337865736305283061
9990077748726922998608279053171691876578860908941817057993404890218441559791092
6768627965975839524839267348836347456516870161662406424242412289611180106156823
4253939218005248345472377921991122859591419187749179382334001007812832650671028
1781396029120914720100947878752551263372884222353869490067927664511634758101193
8753196572421214760382847747745717045786104173857479113019085838778901523343430
1300528279703858035981518292960030568261209195094373732545417105638388704752895
0563961029843641360935641632589408137981511693338619797339821670761004607980096
0160248230969430438069566201232136501405495862506152825880330229083858124784693
1572032323360189946943764772672187937682643182838260356452069946863021604887452
8424363593558622333506235945002890558581611275341783750455936126130852640828051
2138731774902002495527387345859564051608305830537707325339715526204447054295735
3836111367752316997274029294167420442324811387507563131907827218886405337469421
3842169928862940479635305150560788126366206497231257579019598873041195626227343
7289005165611110941117452779654827904712505819990774980638215593768855464988229
3898540829132512907647838632249478101675349169348928810420301561028338614382737
8160946341335383578340765314321417150655877547820252454780657301342277470616744
2419689526131642741046954746214837562882997718041867850845469656191509086958742
5118443583730659095146098045124740941137389992782249298336779601101538709612974
9705566301637307202750734759922943792393824427421186158236161317886392553095117
1884212985083072382597291441422515794038830113590833316518582349672212596218125
0705811375949552502274727467436988713192667076929919908446716122873885845758462
2726573330753735572823951616964175198675012681745429323738294143824814377139861
9067166575729458078048205595118816871880752129718326364421553367877512747669407
9011705750981957508456356521738954417987507452385445520013357203333237989507439
3905312918212255259833790909463630202185353848854825062897715616963860712382771
7256213134605494017704135817319317633701363322528191275471914434509207118488383
6681817426334294961187009150304916533946476371776643912079834749462739782217150
2090670190302469762151278521956142070806461631373236517853976292092025500288962
0129701413796400380557349492690735351459612086747965477336929587736286356601437
6796403843079686413856344780132826128458918489852804804884418082163942397401436
2903481665458114454366460032490618763039502356402044530748210241366895196644221
3392007574791286838051751506346625693919377402835120756662608298904918772878338
5217852279204577184696585527879044756219266399200840930207567392536373562839082
9817577902153202106409617373283598494066652141198183810884515459772895164572131
8977979074919410131483685446396169046070301075968189337412175759881651270007612
6278916951040631585763753478742007022205107089125761236165802680681585849985263
1465878086616800733264676830206391697203064894405628195406190685242003053463156
6218913273090696873531816410945142880366059952202482488867115544291047219291342
4834643870536850864874909917881267056566538719104972182004237149274016446094345
9845392536706132210616533085662021188968234005752675486101476993688738209584552
2115719234796868881608536316158628801503959494185294892270744108282071693033878
1808493620401825522227101098565344481720747075601924591559943107294957819787859
0578940052540122867517142511184356437184053563024181225473266093302710397968091
0649392727226830354104676325913552796838377050198552346212228584105571199217317
1796980433931770775075562705604783177984444763756025463703336924711422081551997
3691371975163241302748712199863404548248524570118553342675264715978310731245663
4298052214554941562527240289153333543493412178620370072603152798707718724912344
9447714790952073476138542548531155277330103034247683586549609372232400715451812
9732692081058424090557725645803681462234493189708138897143299831347617799679712
4537823107037391514738786921191875667003193212818968033226965944592862106074388
2741691946516226763254066507088107103039417886056489376981673415902592519461182
3642945652669372203155504700213598846292758012527715422016629954863130324912311
0296279237238997664168034971412265279319076363261368141455163766565598397884893
8173308266877990196288693229659737995193162118721545528739417024366988559388879
3316744533363119541518404088283815193421234122820030950313341050704760159987985
4725291906652224793197154403317948368373732208218857733416238564413807005419135
3024594391350255453188645479625226025176292837433046510236105758351455073944333
9610216229675461415781127197001738611494279501411253280621254775810512972088465
2631580948066336876701473107335407177108766159358568140982129677307591973829734
4144525668877085532457088895832099382343210271822411476373279135756861542125284
9657903335093152776925505845644010552192644505312073756287744998163646332835816
1403301758139673594273276904489203618803867549557518068900585329272014939235005
2584514670698262854825788326739873522045722823929020714482221988558710289699193
5873074277815159757620764023951243860202032596596250212578349957710085626386118
2338133185090146865770640106762786175837727728958927460394039303372718738505369
1295712671506689668849388088514294360996201296675907922508227531381284985152690
2931700263136328942095797577959327635531162066753488651317323872438748063513314
5126448899675898288129254800764251865864902411111273013571971813816025831785069
3224400799865663537154408845486639318170839573578079905973083909488180406093595
9190907473960904410150516321749681412100765719177483767355751000733616922386537
4290794578032000423374528075661530429290144957806296341383835517835997647088513
4900485697369796523869584599459559209070905895689145114141268450546211794502661
1750166928260250950770778211950432617383223562437601776799362796099368975191394
9650333585071554184364568526166742436889203710374953284259271316105378349807407
3915863381796765842525803673720646935124865223848134166380806150570482905989069
6451936440018597120425723007316410009916987524260377362177763430621616744884930
8109299010095179745415642512048220867145868492551324442667771278637282113315362
2430109182439124338021404624222334915355951689081628848798998827363044537243217
4280215755777967021666317047969728172483392841015642274507271779269399929740308
0727703950135815451424940490265361058254093731146531049433824843797186069372144
4460082679800247122948940576185389220342560830269705287662137737359439422411470
7074072902725461307358541745691419446487624357682397065703184168467540733466346
2936739836200040414007140542776324801327422026853936988697876070095900486846506
2677136307097982100655728510130660101078063374334477307347865388174268123074376
6066643312775356466578603715192922768440458273283243808212841218776132042460464
9008010547314267492608269221556374054862417170310279199969426456209556198164545
4766204502241144940474934983220680719135276798674781345820385957041346617793722
8534940031631599544093684089572533438702986717829770373332806801764639502090023
9419314991150091052768211195109990631661503115855828355826071794100525285836113
6996130344279017381178741206128818206202326384986151565645123004779296756361834
5768105043341769543067538041113928553792529241347339481050532025708728186307291
1589113359420147618726642915640363719276023062838406504254417423354645499870553
1872688792642410214736369862546374715974435494344389973005174252511087735788639
0946812096673428152585919924857640488055071329814299359911463239919113959926752
5763590074465728101918058418073422277347213977232182317717169164001088261125490
9336118678057572239101818616854910850088527227437421208652485237245624869766224
5384819298671129452945515497030585919307198497105414181636968976131126744027009
6486675459345670599369954645005589216280479763656861333165639073957032720343891
7541526750091501119885687270884819553167693168127289214303137681801644547736751
8353497857924276463354162433601125960252109501612264110346083465648235597934274
0568688492244587454937767521203247038030354911575448312952758919398936808763276
8543876955769488142284431199859570072752139317683783177033913042306095899913731
4684569010422095161967070506420256733873446115655276175992727151877660010238944
7605397895169457088027287362251210762240918100667008834747376051562855339435658
4375627124124445765166306408593950794755092046393224520253546363444479175566172
5962187199279186575490857852950012840229035061514937310107009446151011613712423
7614267225417320559592027821293257259471464172249773213163818453265552796042705
4187149623658525245864893325414506264233788565146467060429856478196846159366328
8954299780722542264790400616019751975007460545150060291806638271497016110987951
3366337713784344161940531214452918551801365755586676150193730296919320761200092
5506508158327550849934076879725236998702356793102680413674571895664143185267905
4717169962990363015545645090044802789055701968328313630718997699153166679208958
7685722906009154729196363816735966739599757103260155719202373485805211281174586
1006515259888384311451189488055212914577569914657753004138471712457796504817585
6395072895337539755822087777506072339445587895905719156733
*\bye
No pages of output.
Transcript written on acker42.log.

back to original 2014 answer. Here is the output:

Ackermann numbers

I have also made a variant using xint (although here the involved integers never exceed the TeX limit). Here is its output to show the time penalty due to the use of routines allowing arbitrarily big integers:

update: (2017) I forgot on which computer the timings above were made, but I obtain now about 2x faster execution time with xint 1.2k (2017/01/06) ... but as the question was about being slow ...

Ackermann again

The code using only \numexpr: (remark 2017 understanding syntax is probably as long as executing Ackerman function...)

\catcode`@ 11
\def\gobtozero #10{}

\def\Ackermann #1#2{%
    \romannumeral-`0%
    \expandafter\Ackermann@i\the\numexpr#1\expandafter.\the\numexpr #2.}

\def\Ackermann@i #1#2.#3#4.{%
    \gobtozero #1\Ackermann@RuleA 0%
    \expandafter\Ackermann@i\the\numexpr#1#2-\@ne\expandafter.%
    \romannumeral-`0\gobtozero #3\Ackermann@RuleB 0%
    \expandafter\Ackermann@i\the\numexpr #1#2\expandafter.%
    \the\numexpr #3#4-\@ne..%
}

\def\Ackermann@RuleA 0\expandafter\Ackermann@i
    \the\numexpr 0-\@ne\expandafter.\romannumeral-`0\gobtozero
    #1\Ackermann@RuleB 0\expandafter\Ackermann@i\the\numexpr 0\expandafter.%
    \the\numexpr #2-\@ne..{\the\numexpr #2+\@ne\relax}

\def\Ackermann@RuleB 0\expandafter\Ackermann@i\the\numexpr #1\expandafter.%
    \the\numexpr #2-\@ne.{1}

\catcode`@ 12


\newcount\cnta
\overfullrule 0pt
\hsize 8cm
\nopagenumbers

\cnta0
\noindent\loop 
A(0,\the\cnta)=\Ackermann 0{\cnta}%
\advance\cnta1
\ifnum\cnta<10 ,
\repeat

\cnta0
\noindent\loop 
A(1,\the\cnta)=\Ackermann 1{\cnta}%
\advance\cnta1
\ifnum\cnta<10 ,
\repeat

\cnta0
\noindent\loop 
A(2,\the\cnta)=\Ackermann 2{\cnta}%
\advance\cnta1
\ifnum\cnta<10 ,
\repeat

\cnta0
\noindent\loop 
A(3,\the\cnta)=\Ackermann 3{\cnta}%
\advance\cnta1
\ifnum\cnta<5 ,
\repeat

\cnta 5
\loop\noindent\pdfresettimer
A(3,\the\cnta)=\Ackermann 3{\cnta} 
 (\the\numexpr 100*\the\pdfelapsedtime/65536\relax\space 
       hundredths of a second)\endgraf
\advance\cnta1
\ifnum\cnta<9
\repeat

% mais A(3,9) donne:
%  ERROR: TeX capacity exceeded, sorry [expansion depth=10000].

% \pdfresettimer
% A(3,9)=\Ackermann 39
%  (\the\numexpr 100*\the\pdfelapsedtime/65536\relax\space 
%        hundredths of a second)\endgraf

\bye

The variant using the increment and decrement functions from xint.

\input xint.sty
\catcode`_ 11

\def\Ackermann #1#2{%
    \romannumeral0%
    \expandafter\Ackermann_i\the\numexpr#1\expandafter.\the\numexpr #2.}

\def\Ackermann_i #1#2.#3#4.{%
    \xint_gob_til_zero #1\Ackermann_RuleA 0%
    \expandafter\Ackermann_i\the\numexpr#1#2-\xint_c_i\expandafter.%
    \romannumeral0\xint_gob_til_zero #3\Ackermann_RuleB 0%
    \expandafter\Ackermann_i\the\numexpr #1#2\expandafter.%
    \romannumeral0\xintdec{#3#4}..%
}

\def\Ackermann_RuleA 0\expandafter\Ackermann_i
    \the\numexpr 0-\xint_c_i\expandafter.\romannumeral0\xint_gob_til_zero
    #1\Ackermann_RuleB 0%
    \expandafter\Ackermann_i\the\numexpr 0\expandafter.%
    \romannumeral0\xintdec #2..{\xintinc{#2}}

\def\Ackermann_RuleB 0\expandafter\Ackermann_i\the\numexpr #1\expandafter.%
    \romannumeral0\xintdec #2.{ 1}

\catcode`_ 8
4

A TeX-agnostic solution would simply be putting everything on a floppy and run from that. Typical floppy speed is 30 kilobytes per second which buys you a minute more for each 2 megabytes which needs to be read.

2

A completely different solution. Please use a hadware, as mentioned in my answer here: How was TeX output visualised on screen, back in the day?

2

This is a tricky one, I find:

\documentclass{article}
\usepackage{hyperref}
\makeatletter
\AtBeginDocument{
    \catcode`_=12
    \begingroup\lccode`~=`_
    \lowercase{\endgroup\let~}\sb
    \mathcode`_="8000
}
\makeatother

\begin{document}
\begin{figure}
    \caption{$x_y$}
    \label{z}
\end{figure}
\end{document}

You may need to do this because you are using an equation with subscripts in some figure caption, but there can be other uses as well. Anyway, the effect is drastic.

The above MWE will compile six times instead of once, each time telling you

LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.

So whatever else you do to increase time for a single compilation pass, combine it with this to sextuple your mileage.

(Credit where credit is due: the patch is from here, and there is a fix here.)

0

\usepackage{microtype} is always worth it. Yes, it is a package, but it can be easily justified.

  • 2
    Nice pun :-) Indeed, "it can be easily justified" is the point of microtype. – ShreevatsaR Sep 29 '17 at 17:09
0

This MWE, assuming a file ./gfx/Figure.eps,

\documentclass{article}
\usepackage{graphicx}
\graphicspath{{gfx/}}
\usepackage{grffile}
\usepackage{epstopdf}
\epstopdfsetup{outdir=./gfx/}
\epstopdfDeclareGraphicsRule{.eps}{pdf}{.pdf}{epstopdf #1 --outfile=\OutputFile}
\begin{document}
    \includegraphics{Figure.eps}
\end{document}

... takes 5 seconds to compile and an extra 5 seconds for each additional figure file. Some discussion is here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.