\input gets slower after each \input

Phelype Oleinik phe.h.o1 at gmail.com
Tue Apr 27 01:19:51 CEST 2021


Dear list,

I was doing some tests with file reading and I found that \input gets
a tiny bit slower each time it is used.  Why is that?

I made a test document that shows this behaviour.  It creates an empty
file |abc...xyz.tex|, inputs that file 10000 times and prints the time
it took.  Each iteration of this process takes a bit longer than the
previous (this grows linearly).  I tested with different name lengths
and the impact on the test result is minimal.  On my machine I get:

0.36674pt
0.89546pt
1.39313pt
1.80832pt
2.27615pt
2.76115pt
3.52126pt
4.09816pt
4.6648pt

(pt is now an unit of time, it seems :-)

The example uses the pdfTeX primitives |\pdfresettimer| and
|\pdfelapsedtime|, so if you want to run with another engine you need to
adjust those primitives.  Here's the test file:

     % any file that can be created empty:
     \def\name{abcdefghijklmnopqrstuvwxyz.tex}%
     \def\test{%
       \batchmode \pdfresettimer \a \errorstopmode
       \message{\the\dimexpr \pdfelapsedtime sp\relax}}
     \def\a{\b\b\b\b\b\b\b\b\b\b} % 10
     \def\b{\c\c\c\c\c\c\c\c\c\c} % 100
     \def\c{\d\d\d\d\d\d\d\d\d\d} % 1000
     \def\d{\e\e\e\e\e\e\e\e\e\e} % 10000
     \def\e{\input{\name}}

     % create the file
     \immediate\openout0{\name}
     \immediate\closeout0

     \message{testing \string\input}
     % Each \test will run \input 10000 times.
     % Each run of \test gets slower than the previous
     \test \test \test \test \test
     \test \test \test \test \test

     \bye

Best regards,
Phelype


More information about the tex-live mailing list.