Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I was wondering why a tikz/pgf plot of a data file containing several thousand data points needs a couple of minutes to compile while creating the same plot with a WYSIWYG plotting tool (like Grace) or spreadsheet application (like MS Excel or Origin) needs only seconds. What are the WYSIWYG applications doing differently from tikz to be so much faster?

share|improve this question
    
You should convert both outputs into .pdf to make a fair comparison. –  percusse Jan 23 '12 at 10:03
    
@percusse: Good point. But with Origin for example exporting the graph to .pdf works almost instantaneously. –  Philipp Jan 23 '12 at 10:20
    
As far as I know, TeX is just very ill-suited for this kind of task. My guess would be that external programs really make an image and then export that to pdf instead of having to position every element separately. Note that you can make TikZ use gnuplot to do the plotting, which should speed things up considerably. –  Roelof Spijker Jan 23 '12 at 10:59
    
@wh1t3: Can you explain what you mean by "make an image" because the resulting pdf is still vectorized? –  Philipp Jan 23 '12 at 11:09
    
@Philipp You are underestimating the engine of Excel and Origin. TeX is doing its best to hard-code the .pdf image point by point whereas the others use lots of readily available and RAM-loaded libraries for these, even taking advantage of the graphics card's GPU in some cases. Hence it is not just an algorithm issue. –  percusse Jan 23 '12 at 11:14

2 Answers 2

up vote 7 down vote accepted

Apart from reading out data files, typesetting of data also involves floating point operations, such as transformation of data points into the coordinate system of the output medium (document page). By design, TeX has only very limited support for floating point operations. They must be implemented on top of it as macros (Pgf, fp, LaTeX3) or delegated to the next conversion step of the document creating work flow (PSTricks). Obviously, mathematical operations like sin or exp are much slower if implemented as macros. Nevertheless, TikZ/PGF can be configured to do the plotting step only once for every graph. Repeated document compilation then uses the existing graphics files of the plots.

share|improve this answer
    
Thanks for the answer. So, if TeX is the slow part, would it be considerably faster to use an external tool like asymptote to speed up the compilation? –  Philipp Jan 23 '12 at 11:39
    
Although very powerful, Asymptote is yet another programming language that must be learned, while TikZ/PGF uses familiar (La)TeX concepts. I would first look at the galeries on the project or amateur web sites and then make a decision. To me, compilation speed would be the least important criterion. –  AlexG Jan 23 '12 at 11:55
    
I also think that TikZ/PGF is easier to use and my comment was meant to inquire after potential weaknesses of using such tools. Maybe the integration into the LaTeX document uses up a lot of time or something like this so that this option wouldn't be a useful one. –  Philipp Jan 23 '12 at 12:02

TikZ/PGF and LaTeX/TeX mark-up are interpreted languages, that is the programs are only indirectly executed ("interpreted") by an interpreter program (in this case ultimately by the pdf(TeX) executable). This can be contrasted with a compiled language which is converted into machine code and then 'directly' executed by the host CPU. Programs written for example in C++ or C, as the ones you are quoting will be by nature very much faster.

Another issue is the perceived speed. While you inputting data in a GUI program, the program in all probability is already doing some work. This is very common for example in web-browsers. If one could compare the actual CPU time durations the differences would be marginal.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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