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:

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.

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.
latexwith or without\usepackage[utf8]{inputenc}; it seems to me that it does delay the computation. – Mateus Araújo Jun 21 '11 at 01:47