-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmain.rs
98 lines (77 loc) · 2.16 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#![feature(test)]
extern crate test;
use test::{Bencher, black_box};
use ramhorns::Content;
use serde_derive::Serialize;
use askama::Template;
static SOURCE: &str = "<title>{{title}}</title><h1>{{ title }}</h1><div>{{{body}}}</div>";
#[derive(Content, Serialize, Template)]
#[template(source = "<title>{{title}}</title><h1>{{ title }}</h1><div>{{body|safe}}</div>", ext = "html")]
struct Post<'a> {
title: &'a str,
body: &'a str,
}
#[bench]
fn a_simple_ramhorns(b: &mut Bencher) {
use ramhorns::Template;
let tpl = Template::new(SOURCE).unwrap();
let post = Post {
title: "Hello, Ramhorns!",
body: "This is a really simple test of the rendering!",
};
b.iter(|| {
black_box(tpl.render(&post))
});
}
#[bench]
fn b_simple_wearte(b: &mut Bencher) {
use wearte::Template;
#[derive(Serialize, Template)]
#[template(source = "<title>{{title}}</title><h1>{{ title }}</h1><div>{{{body}}}</div>", ext = "html")]
struct Post<'a> {
title: &'a str,
body: &'a str,
}
let post = Post {
title: "Hello, Ramhorns!",
body: "This is a really simple test of the rendering!",
};
b.iter(|| {
black_box(post.call())
});
}
#[bench]
fn c_simple_askama(b: &mut Bencher) {
use askama::Template;
let post = Post {
title: "Hello, Ramhorns!",
body: "This is a really simple test of the rendering!",
};
b.iter(|| {
black_box(post.render())
});
}
#[bench]
fn d_simple_mustache(b: &mut Bencher) {
let tpl = mustache::compile_str(SOURCE).unwrap();
let post = Post {
title: "Hello, Ramhorns!",
body: "This is a really simple test of the rendering!",
};
b.iter(|| {
black_box(tpl.render_to_string(&post))
});
}
#[bench]
fn e_simple_handlebars(b: &mut Bencher) {
use handlebars::Handlebars;
let mut handlebars = Handlebars::new();
handlebars.register_template_string("t1", SOURCE).unwrap();
let post = Post {
title: "Hello, Ramhorns!",
body: "This is a really simple test of the rendering!",
};
b.iter(|| {
black_box(handlebars.render("t1", &post))
});
}