Skip to content

Djot-PHP Performance Summary

Performance benchmarks for djot-php compared to other implementations.

Test Environment:

  • PHP 8.4.15
  • Node.js v18.19.1
  • Python 3.12.3
  • Rust (jotdown 0.7)
  • Go (godjot)
  • Linux 6.8.0-88-generic

Quick Reference

Document SizePHP FullThroughput
1 KB0.36 ms~3.0 MB/s
10 KB3.7 ms~3.0 MB/s
56 KB18 ms~3.0 MB/s
225 KB80 ms~2.7 MB/s
1 MB456 ms~2.4 MB/s

PHP Alternatives Comparison

With equivalent features enabled (tables, footnotes, smart typography):

Library30KB DocThroughputvs djot-php
erusev/parsedown1.69 ms16.0 MB/s6.7x faster
michelf/php-markdown5.16 ms5.2 MB/s2.2x faster
michelf/php-markdown (Extra)6.15 ms4.4 MB/s1.9x faster
djot-php11.36 ms2.6 MB/sbaseline
league/commonmark (GFM)15.00 ms1.8 MB/s1.3x slower
league/commonmark15.31 ms1.8 MB/s1.4x slower
league/commonmark (Full)23.54 ms1.3 MB/s2.1x slower

Key finding: djot-php is 2x faster than CommonMark when both have equivalent features (tables, footnotes, smart punct) enabled.

Cross-Language Comparison

Benchmarked on medium-sized documents (~56 KB):

ImplementationMean TimeThroughputvs PHP
Rust (jotdown)~1-2 ms~30+ MB/s~10x faster
Go (godjot)~2-4 ms~15+ MB/s~5x faster
JS (@djot/djot)8.1 ms5.2 MB/s2.2x faster
PHP (djot-php)18 ms3.0 MB/sbaseline
Python-Markdown*41.1 ms1.0 MB/s2.3x slower

*Python libraries are Markdown parsers (no Djot implementation exists for Python).

Document Size Scaling

PHP djot-php scales linearly with document size:

SizeInputMean TimeThroughput
tiny1.1 KB0.36 ms3.0 MB/s
small11.1 KB3.68 ms3.0 MB/s
medium56.1 KB18.44 ms3.0 MB/s
large225.5 KB80.42 ms2.7 MB/s
huge1.1 MB456.16 ms2.4 MB/s

Content Type Performance

Different content types have varying performance characteristics:

Content TypeSizeMean TimeThroughputNotes
code_heavy5.8 KB0.71 ms8.0 MB/sFastest - simple parsing
tables9.2 KB5.67 ms1.6 MB/sTable parsing overhead
nested_lists5.6 KB2.37 ms2.3 MB/sAverage
complex8.9 KB4.09 ms2.1 MB/sMany features
inline_heavy14.8 KB8.73 ms1.7 MB/sMany inline elements

Code-heavy documents are fastest because code blocks require minimal parsing.

Profile Performance

Different profiles have similar performance since they filter the same AST:

ProfileMean TimeNotes
none20.70 msNo filtering
full22.10 msAll features enabled
article21.80 msBlog/article content
comment23.27 msUser comments
minimal22.90 msBasic text formatting

Safe Mode

Safe mode has negligible performance impact:

ModeMean Time
Disabled20.01 ms
Enabled20.54 ms

Memory Usage

Memory scales approximately linearly with document size:

Input SizePeak MemoryRatio
11 KB72 MB~6500x
57 KB72 MB~1260x
226 KB72 MB~320x
1 MB~80 MB~80x

Note: PHP has a base memory overhead. The incremental memory per input byte is approximately 30-45x.

Running Benchmarks

bash
# Internal PHP benchmark
php tests/benchmark/benchmark.php

# PHP alternatives comparison
cd tests/benchmark_alternatives
composer install
php benchmark.php

# Cross-language comparison
./tests/benchmark/run-all.sh --compare

Key Takeaways

  1. Throughput: PHP djot-php processes ~3.0 MB/s of djot content
  2. vs CommonMark (Full): djot-php is 2x faster with equivalent features
  3. vs Parsedown: Parsedown is 6-7x faster but lacks advanced features
  4. Scaling: Performance scales linearly with document size (O(n))
  5. vs Rust/Go: Native implementations are 5-10x faster (as expected)
  6. vs JavaScript: Reference JS implementation is ~2x faster
  7. Safe mode: No significant performance penalty
  8. 31% optimization: Recent optimizations improved from 26ms to 18ms (medium doc)

Released under the MIT License.