Measurement method for Sphinx build time (time command and Measure-Command)#

When building and operating a multilingual site with Sphinx, the time required to build the document may gradually increase. The first step in improving performance is to understand how much time the current build process is taking.

This article summarizes the basic method for easily measuring the processing time of Sphinx builds.

For Linux/macOS: time command#

In Unix environments such as Linux and macOS, you can easily measure the time taken to execute any command by using the time command as shown below.

time sphinx-build -E -a -b html ./source ./build _build/ja -D ja

Example shown after execution:

real    0m12.345s
user    0m10.678s
sys     0m1.234s
  • real is the actual time elapsed (wall clock time)

  • user is the CPU time used in user space (Python processing, etc.)

  • sys is the CPU time used in system space (file I/O, etc.)

This method is the easiest and allows you to know the total time required without complicated preparation.


For Windows: Measure-Command (PowerShell)#

The time command is not available in a Windows environment. Instead, use PowerShell’s Measure-Command to measure processing time.

Measure-Command { sphinx-build -E -a -b html ./source ./build _build/ja -D ja }

Example of execution result:

TotalSeconds      : 10.657

In this way, you can check the time taken to execute a command using the TotalSeconds and TotalMilliseconds items.


Supplement: How to embed measurements in Python code#

As an OS-independent method, it is also effective to log processing time using the time module in your Python code.

import time

start = time.time()
# 処理...
elapsed = time.time() - start
print(f"処理時間: {elapsed:.2f}秒")

If you are calling Sphinx from a custom command or setup.py, you can embed these measurements to understand the time for each language and the details of each process.


summary#

For static site generators like Sphinx, understanding the processing time is the first step to improving operations. Use the following methods depending on the situation:

  • Linux/macOS: time command (easiest)

  • Windows: Measure-Command (PowerShell standard)

  • Cross-platform: Python’s time module

In the future, we plan to use these measurement results to make gradual improvements, such as deleting unnecessary caches and introducing parallel builds.

Article information

author:

Mr. Takagi

Post date:

2025-05-26