Skip to content

Collected benchmarks for templating crates written in Rust

Notifications You must be signed in to change notification settings

asalvi0/template-benchmarks-rs

 
 

Repository files navigation

Rust template engine benchmarks

This repo tries to assess Rust template engine performance. Templating engines are grouped into two broad categories:

Compiled Templates

These engines require you to rebuild when a template changes.

  • write!: The std library write! macro
  • Askama: Type-safe, compiled Jinja-like templates for Rust
  • Horrorshow: A macro-based html builder for rust
  • Ructe: Rust Compiled Templates with static-file handling
  • fomat: Alternative syntax for printing macros in Rust
  • Markup: A blazing fast, type-safe template engine for Rust
  • Maud: Compile-time HTML templates for Rust
  • Sailfish: Simple, small, and extremely fast template engine for Rust

Runtime Templates

These engines do not require a rebuild of your rust codebase when a template changes.

  • Handlebars: Rust templating with Handlebars
  • Tera: A template engine for Rust based on Jinja2/Django
  • Liquid: Liquid templating for Rust
  • MiniJinja: A powerful but minimal dependency template engine for Rust compatible with Jinja/Jinja2
  • Ramhorns: Fast Mustache template engine implementation in pure Rust

Results

These results are from Feb 29, 2024 (rustc 1.76.0), running on an MacBook Pro 16 (M1 Pro)

As a violin plot generated by Criterion:

Big table violin plot

Compiled:
Big table/write         time:   [194.89 µs 195.25 µs 195.70 µs]
Big table/Askama        time:   [275.72 µs 278.23 µs 281.60 µs]
Big table/Horrorshow    time:   [136.20 µs 137.39 µs 139.26 µs]
Big table/Ructe         time:   [153.43 µs 154.46 µs 155.39 µs]
Big table/fomat         time:   [182.18 µs 183.13 µs 184.03 µs]
Big table/Markup        time:   [114.37 µs 114.97 µs 115.62 µs]
Big table/Maud          time:   [62.747 µs 63.124 µs 63.500 µs]
Big table/Sailfish      time:   [16.585 µs 16.614 µs 16.648 µs]

Runtime:
Big table/Handlebars    time:   [2.9513 ms 2.9587 ms 2.9662 ms]
Big table/Tera          time:   [684.66 µs 688.46 µs 692.18 µs]
Big table/Liquid        time:   [3.6415 ms 3.6503 ms 3.6593 ms]
Big table/MiniJinja     time:   [651.67 ns 653.44 ns 655.33 ns]
Big table/Ramhorns      time:   [229.10 µs 230.08 µs 231.09 µs]

Teams violin plot

Compiled:
Teams/write             time:   [403.01 ns 406.95 ns 412.73 ns]
Teams/Askama            time:   [348.69 ns 349.49 ns 350.37 ns]
Teams/Horrorshow        time:   [235.10 ns 235.76 ns 236.43 ns]
Teams/Ructe             time:   [366.40 ns 366.98 ns 367.68 ns]
Teams/fomat             time:   [289.13 ns 289.96 ns 290.88 ns]
Teams/Markup            time:   [151.60 ns 151.98 ns 152.38 ns]
Teams/Maud              time:   [102.45 ns 102.58 ns 102.72 ns]
Teams/Sailfish          time:   [74.462 ns 74.591 ns 74.727 ns]

Runtime:
Teams/Handlebars        time:   [2.8109 µs 2.8199 µs 2.8295 µs]
Teams/Tera              time:   [1.9678 µs 1.9728 µs 1.9784 µs]
Teams/Liquid            time:   [3.6899 µs 3.6976 µs 3.7059 µs]
Teams/MiniJinja         time:   [1.4805 µs 1.4889 µs 1.4980 µs]
Teams/Ramhorns          time:   [310.73 ns 311.25 ns 311.82 ns]

Running the benchmarks

cargo bench

Plots will be rendered if gnuplot is installed and will be available in the target/criterion folder.

About

Collected benchmarks for templating crates written in Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 96.0%
  • HTML 3.4%
  • Shell 0.6%