2017-07-04 12:27:32 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate tera;
|
2018-10-31 07:18:57 +00:00
|
|
|
extern crate test;
|
2017-07-04 12:27:32 +00:00
|
|
|
|
2018-05-03 18:50:30 +00:00
|
|
|
extern crate config;
|
2017-07-04 12:27:32 +00:00
|
|
|
extern crate front_matter;
|
2018-10-31 07:18:57 +00:00
|
|
|
extern crate rendering;
|
2017-07-04 12:27:32 +00:00
|
|
|
|
|
|
|
use std::collections::HashMap;
|
2018-08-25 23:13:15 +00:00
|
|
|
use std::path::Path;
|
2017-07-04 12:27:32 +00:00
|
|
|
|
2018-05-03 18:50:30 +00:00
|
|
|
use config::Config;
|
2018-10-31 07:18:57 +00:00
|
|
|
use front_matter::InsertAnchor;
|
|
|
|
use rendering::{render_content, render_shortcodes, RenderContext};
|
|
|
|
use tera::Tera;
|
2017-07-04 12:27:32 +00:00
|
|
|
|
|
|
|
static CONTENT: &'static str = r#"
|
|
|
|
# Modus cognitius profanam ne duae virtutis mundi
|
|
|
|
|
|
|
|
## Ut vita
|
|
|
|
|
|
|
|
Lorem markdownum litora, care ponto nomina, et ut aspicit gelidas sui et
|
|
|
|
purpureo genuit. Tamen colla venientis [delphina](http://nil-sol.com/ecquis)
|
|
|
|
Tusci et temptata citaeque curam isto ubi vult vulnere reppulit.
|
|
|
|
|
|
|
|
- Seque vidit flendoque de quodam
|
|
|
|
- Dabit minimos deiecto caputque noctis pluma
|
|
|
|
- Leti coniunx est Helicen
|
|
|
|
- Illius pulvereumque Icare inpositos
|
|
|
|
- Vivunt pereo pluvio tot ramos Olenios gelidis
|
|
|
|
- Quater teretes natura inde
|
|
|
|
|
|
|
|
### A subsection
|
|
|
|
|
|
|
|
Protinus dicunt, breve per, et vivacis genus Orphei munere. Me terram [dimittere
|
|
|
|
casside](http://corpus.org/) pervenit saxo primoque frequentat genuum sorori
|
|
|
|
praeferre causas Libys. Illud in serpit adsuetam utrimque nunc haberent,
|
|
|
|
**terrae si** veni! Hectoreis potes sumite [Mavortis retusa](http://tua.org/)
|
|
|
|
granum captantur potuisse Minervae, frugum.
|
|
|
|
|
|
|
|
> Clivo sub inprovisoque nostrum minus fama est, discordia patrem petebat precatur
|
|
|
|
absumitur, poena per sit. Foramina *tamen cupidine* memor supplex tollentes
|
|
|
|
dictum unam orbem, Anubis caecae. Viderat formosior tegebat satis, Aethiopasque
|
|
|
|
sit submisso coniuge tristis ubi!
|
|
|
|
|
|
|
|
## Praeceps Corinthus totidem quem crus vultum cape
|
|
|
|
|
|
|
|
```rs
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Site {
|
|
|
|
/// The base path of the gutenberg site
|
|
|
|
pub base_path: PathBuf,
|
|
|
|
/// The parsed config for the site
|
|
|
|
pub config: Config,
|
|
|
|
pub pages: HashMap<PathBuf, Page>,
|
|
|
|
pub sections: HashMap<PathBuf, Section>,
|
|
|
|
pub tera: Tera,
|
|
|
|
live_reload: bool,
|
|
|
|
output_path: PathBuf,
|
|
|
|
static_path: PathBuf,
|
|
|
|
pub tags: Option<Taxonomy>,
|
|
|
|
pub categories: Option<Taxonomy>,
|
|
|
|
/// A map of all .md files (section and pages) and their permalink
|
|
|
|
/// We need that if there are relative links in the content that need to be resolved
|
|
|
|
pub permalinks: HashMap<String, String>,
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## More stuff
|
|
|
|
And a shortcode:
|
|
|
|
|
|
|
|
{{ youtube(id="my_youtube_id") }}
|
|
|
|
|
|
|
|
### Another subsection
|
|
|
|
Gotta make the toc do a little bit of work
|
|
|
|
|
|
|
|
# A big title
|
|
|
|
|
|
|
|
- hello
|
|
|
|
- world
|
|
|
|
- !
|
|
|
|
|
|
|
|
```py
|
|
|
|
if __name__ == "__main__":
|
|
|
|
gen_site("basic-blog", [""], 250, paginate=True)
|
|
|
|
```
|
|
|
|
"#;
|
|
|
|
|
|
|
|
#[bench]
|
2018-05-06 20:58:39 +00:00
|
|
|
fn bench_render_content_with_highlighting(b: &mut test::Bencher) {
|
|
|
|
let mut tera = Tera::default();
|
|
|
|
tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
|
2017-07-04 12:27:32 +00:00
|
|
|
let permalinks_ctx = HashMap::new();
|
2018-05-06 20:58:39 +00:00
|
|
|
let config = Config::default();
|
2018-10-31 07:18:57 +00:00
|
|
|
let context =
|
|
|
|
RenderContext::new(&tera, &config, "", &permalinks_ctx, Path::new(""), InsertAnchor::None);
|
2018-05-06 20:58:39 +00:00
|
|
|
b.iter(|| render_content(CONTENT, &context).unwrap());
|
2017-07-04 12:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2018-05-06 20:58:39 +00:00
|
|
|
fn bench_render_content_without_highlighting(b: &mut test::Bencher) {
|
|
|
|
let mut tera = Tera::default();
|
|
|
|
tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
|
2017-07-04 12:27:32 +00:00
|
|
|
let permalinks_ctx = HashMap::new();
|
2018-05-06 20:58:39 +00:00
|
|
|
let mut config = Config::default();
|
|
|
|
config.highlight_code = false;
|
2018-10-31 07:18:57 +00:00
|
|
|
let context =
|
|
|
|
RenderContext::new(&tera, &config, "", &permalinks_ctx, Path::new(""), InsertAnchor::None);
|
2018-05-06 20:58:39 +00:00
|
|
|
b.iter(|| render_content(CONTENT, &context).unwrap());
|
2017-07-04 12:27:32 +00:00
|
|
|
}
|
2018-05-03 18:50:30 +00:00
|
|
|
|
|
|
|
#[bench]
|
2018-05-06 20:58:39 +00:00
|
|
|
fn bench_render_content_no_shortcode(b: &mut test::Bencher) {
|
|
|
|
let tera = Tera::default();
|
|
|
|
let content2 = CONTENT.replace(r#"{{ youtube(id="my_youtube_id") }}"#, "");
|
|
|
|
let mut config = Config::default();
|
|
|
|
config.highlight_code = false;
|
|
|
|
let permalinks_ctx = HashMap::new();
|
2018-10-31 07:18:57 +00:00
|
|
|
let context =
|
|
|
|
RenderContext::new(&tera, &config, "", &permalinks_ctx, Path::new(""), InsertAnchor::None);
|
2018-05-03 18:50:30 +00:00
|
|
|
|
2018-05-06 20:58:39 +00:00
|
|
|
b.iter(|| render_content(&content2, &context).unwrap());
|
2018-05-03 18:50:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2018-05-06 20:58:39 +00:00
|
|
|
fn bench_render_shortcodes_one_present(b: &mut test::Bencher) {
|
2018-05-03 18:50:30 +00:00
|
|
|
let mut tera = Tera::default();
|
|
|
|
tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
|
2018-07-01 14:14:46 +00:00
|
|
|
let config = Config::default();
|
|
|
|
let permalinks_ctx = HashMap::new();
|
2018-10-31 07:18:57 +00:00
|
|
|
let context =
|
|
|
|
RenderContext::new(&tera, &config, "", &permalinks_ctx, Path::new(""), InsertAnchor::None);
|
2018-05-03 18:50:30 +00:00
|
|
|
|
2018-07-01 14:14:46 +00:00
|
|
|
b.iter(|| render_shortcodes(CONTENT, &context));
|
2018-05-03 18:50:30 +00:00
|
|
|
}
|