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 have done a benchmark on the same machine for the same input file. I got surprised, the time needed by xelatex is almost 2.9 times as the time needed by latex-dvips-ps2pdf. For the sake of simplicity, I duplicated the input file: xlx.tex for xelatex and ltx.tex for latex-dvips-ps2pdf. See the following result.

Results:

enter image description here

Legends:

  • xlx.tex : input file for xelatex.
  • xlx.pdf : pdf output without gs compression.
  • xlx-tiny.pdf : pdf output with gs compression.
  • ltx.tex : input file for latex.
  • ltx.pdf : pdf output without gs compression.
  • ltx-tiny.pdf : pdf output with gs compression.

enter image description here

Even if ps2pdf already compressed its output, it is still worth compressing the output again using gs. However, the compression ratio is too small.

C# code for benchmarking:

It is not a clean code that conforms to best practice. I will tidy it up.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace LaTeXAutomator
{
    class Program
    {
        class Record
        {
            public string Activity { get; set; }
            public double Elapsed { get; set; }
            public override string ToString()
            {
                return string.Format("{0}: {1} seconds", Activity, Elapsed);
            }
        }
        class Step
        {
            public string FileName { get; set; }
            public string Arguments { get; set; }
            public bool UseShellExecute { get; set; }
            public void Start()
            {
                Process p = new Process();
                p.StartInfo.FileName = FileName;
                p.StartInfo.Arguments = Arguments;
                p.StartInfo.UseShellExecute = UseShellExecute;

                p.EnableRaisingEvents = true;
                p.Exited += (sender, e) => { Console.WriteLine("=== {0} FINISHED ===", FileName.ToUpper()); };

                p.Start();
                p.WaitForExit();
                //p.Close();
            }
        }

        static void Main(string[] args)
        {
            var records = new List<Record>();


            var filename = "xlx"; // for xelatex
            var xelatexSteps = new List<Step>()
            {
                new Step { FileName = "xelatex", Arguments = String.Format("-interaction=nonstopmode {0}.tex", filename), UseShellExecute = false },
                new Step { FileName = "xelatex", Arguments = String.Format("-interaction=nonstopmode {0}.tex", filename), UseShellExecute = false },
                new Step { FileName = "gswin64c", Arguments =  String.Format("-sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile={0}-tiny.pdf {0}.pdf", filename), UseShellExecute = false }//,
                //new Step { FileName = "AcroRd32", Arguments =  String.Format("{0}-tiny.pdf", filename), UseShellExecute = true }
            };
            DoBenchMark(xelatexSteps, records);
            CleanUp(filename);


            filename = "ltx"; // for latex
            var latexSteps = new List<Step>()
            {
                new Step { FileName = "latex", Arguments = String.Format("-interaction=nonstopmode {0}.tex", filename), UseShellExecute = false },
                new Step { FileName = "latex", Arguments = String.Format("-interaction=nonstopmode {0}.tex", filename), UseShellExecute = false },
                new Step { FileName = "dvips", Arguments =  String.Format("{0}.dvi", filename), UseShellExecute = false },
                new Step { FileName = "ps2pdf", Arguments =  String.Format("{0}.ps", filename), UseShellExecute = false },
                new Step { FileName = "gswin64c", Arguments =  String.Format("-sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile={0}-tiny.pdf {0}.pdf", filename), UseShellExecute = false }//,
                //new Step { FileName = "AcroRd32", Arguments =  String.Format("{0}-tiny.pdf", filename), UseShellExecute = true }
            };
            DoBenchMark(latexSteps, records);
            CleanUp(filename);
            Console.Clear();

            foreach (var x in records)
            {
                Console.WriteLine(x);
            }

            var totalXeTeX = records.Take(xelatexSteps.Count).Sum(x => x.Elapsed);
            var totalLaTeX = records.Skip(xelatexSteps.Count).Sum(x => x.Elapsed);

            Console.WriteLine("==========================");
            Console.WriteLine("Total time taken by XeLaTeX: {0} seconds.", totalXeTeX);
            Console.WriteLine("Total time taken by LaTeX: {0} seconds.", totalLaTeX);

            var ratio = totalXeTeX / totalLaTeX;

            Console.WriteLine("XeLaTeX runs {0} times slower than LaTeX.", ratio);


        }

        private static void DoBenchMark(List<Step> steps, List<Record> records)
        {
            Stopwatch sw = new Stopwatch();
            foreach (var step in steps)
            {
                sw.Reset();
                sw.Start();
                step.Start();
                sw.Stop();
                records.Add(new Record { Activity = step.FileName, Elapsed = sw.Elapsed.TotalSeconds });
            }
        }

        private static void CleanUp(string filename)
        {
            foreach (var filepath in Directory.GetFiles(".", String.Format("{0}.*", filename), SearchOption.TopDirectoryOnly))
            {
                if (!(Path.GetExtension(filepath) == ".tex" || Path.GetExtension(filepath) == ".pdf"))
                    File.Delete(filepath);
            }

        }
    }
}

Question:

Why does xelatex execute much much slower than latex-dvips-ps2pdf?

Note: The speed is very crucial because my online TeX to PDF generator should execute as fast as possible.

Comment from TH. and my response:

I don't think this is a very good question. What sort of answer would you be looking for? "It's slower because it is." "It's slower because it implements foo differently than pdfTeX." "It's slower because it uses feature bar." Are any of those actually useful to you?

All your assumptions above are very useful for me.

share|improve this question
1  
@xport: It's better to use PowerShell - Timing a command's execution in PowerShell. And defragment the hard drive. And even better - load the entire LaTeX distribution in RAM Drive. –  Karl Karlsson Jun 10 '11 at 11:05
2  
@Karl: I don't believe it can boost the xelatex performance significantly. –  xport Jun 10 '11 at 11:08
3  
@xport, Could you please provide the contents of the TeX file please? Perhaps they are important too. –  pmav99 Jun 10 '11 at 11:12
2  
I don't think this is a very good question. What sort of answer would you be looking for? "It's slower because it is." "It's slower because it implements foo differently than pdfTeX." "It's slower because it uses feature bar." Are any of those actually useful to you? –  TH. Jun 15 '11 at 9:13
1  
Irrespective of cpu there can be a difference of read speed because something is read from the HDD rather than the RAM or the other way around. –  N.N. Jun 15 '11 at 12:51

1 Answer 1

To know why it's slower one first must determine where it's slower. I make two assumptions:

  1. XeTeX is that much slower not always, but only in particular cases.
  2. XeTeX is that much slower, because it makes that big file.

In 2 I mean, there is some effort in making that file, and this effort is what goes wrong. Not the I/O associated with the file creation. Normally latex-dvips-gs and pdflatex produce files that aren't compressible by ghostscript.

It's clear, that a PDF made by 1 kB TeX file can't have a 16 MB size because of textual data. Than, re-reading I saw that there is a folder called Images. So, my guess is:

It's something to do with the images. Try turning them off 1) and lets see what happens.

1) This means commenting out, replacing with dummy images of lowest possible complexity, etc.

share|improve this answer
6  
My gut feeling is also an image issue. Possibly there is an image that can be copied verbatim by dvips, but not by dvipdfmx. But regardless, i think this is an ill-thought out question, as it requires an oracle or other paranormal means to answer correctly. There is neither input nor output files so there is no means of testing anything. If this happened with me in a commercial setting, i would have closed the issue immediately with 'Unable to reproduce' as reason. –  Taco Hoekwater Jun 21 '11 at 16:30
    
@Taco: You can make any dummy input files and let me know if xelatex can do faster. I will prepare the dummy input files later. I am still struggling against other issues now. –  xport Jun 21 '11 at 18:29
1  
@xport: For example, testmath.tex compiles as follows. LaTeX ~ 7.8 s, PDFLaTeX ~ 6.5 s, XeLaTeX ~ 8.7 s. That's an average after OS file caching starts to work i.e. after the 2nd or 3rd run. First run is quite slow, because of the hard drive. And yes, XeLaTeX is slower, but it's not times slower. –  Karl Karlsson Jun 21 '11 at 20:18
    
that matches my experience too –  Taco Hoekwater Jun 23 '11 at 19:47

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.