Skip to content

Instantly share code, notes, and snippets.

@bketelsen
Created April 5, 2022 19:06
Show Gist options
  • Save bketelsen/2d12cdebe0e03a563862a27096f6a65d to your computer and use it in GitHub Desktop.
Save bketelsen/2d12cdebe0e03a563862a27096f6a65d to your computer and use it in GitHub Desktop.
benchmark_template.rs
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use bartholomew::content::Content;
use std::path::PathBuf;
fn doit(n: u64) -> Result<(), anyhow::Error> {
let doc: String = r#"title = "The Goals of Bartholomew"
description = "We have plans. Big plans. Actually, they're small plans."
date = "2021-12-23T17:05:19Z"
tags = ["bartholomew"]
[extra]
author = "Matt Butcher"
author_page = "/author/butcher"
---
Bartholomew is intended to be three things:
1. A simple-to-use CMS-like system that feels like Jekyll or other static site generators
2. A flexible system that is cheap to run, but easy to extend. (Cloud is expensive!)
3. An exhibition of the value of WebAssembly on the server-side
Static site generators are great for many things. But they are also limiting. To keep
a site feeling fresh, you have to keep building and publishing the site because all
elements are rendered at build time. If you want to write dynamic elements of any sort,
you have to resort to JavaScript.
But at the same time, these static site generators are super easy to use. Content is
just written in plain text, and is rendered into HTML. Menus and navigation are
built up automatically. And dealing with images and other files is as easy as dropping
a file in a directory. We love that experience. So we tried to combine the best of the
static site generator with a server-side technology.
{{ alert "warning" "Bartholomew is a work in progress" }}"#.to_string();
let script_path = PathBuf::from("./shortcodes/");
let contents: Content = doc.parse()?;
let mut c = Content::new(contents.head, contents.body, script_path);
let _out = c.render_markdown();
Ok(())
}
fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("render content template", |b| b.iter(|| doit(black_box(1))));
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
@bketelsen
Copy link
Author

render content template time:   [459.67 us 460.79 us 461.96 us]                                    
                        change: [-1.8546% -0.9871% +0.0853%] (p = 0.04 < 0.05)
                        Change within noise threshold.
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) high mild
  2 (2.00%) high severe

@bketelsen
Copy link
Author

using two Content structs because the script path is different inside WASI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment