zola/components/rendering/benches/all.rs

160 lines
4.7 KiB
Rust
Raw Normal View History

#![feature(test)]
extern crate test;
2017-07-04 12:27:32 +00:00
use std::collections::HashMap;
2018-05-03 18:50:30 +00:00
use config::Config;
2018-10-31 07:18:57 +00:00
use front_matter::InsertAnchor;
Shortcodes (#1640) * Next version * Added tests for shortcode insertion * Added TOC tests * Added test for #1475 and #1355 * Basic internal / external links tests * Added integration test * Added pseudocode and started on logos * Logos parsing for shortcodes * Fixed string literal parsing Moved string literal parsing to a new lexer in order to have greater control of control characters which are parsed. This fixes the bug that was present in the `string_from_quoted` function and also moves the `QuoteType` to be in the `ArgValueToken`. * Moved string literal logic to seperate module * Added square bracket notation for variables * Error handling rewritten Remove the Result from the `fetch_shortcodes` function. Added proper messages within the internal parsing. * Reorganized and documented the shortcode submodule * Added all logic for ShortcodeContext spans * Added working insertion code for MD files * Made functions generic over Markdown or HTML * Add check for embedding bodies * Structure of main function clear * Added test for `new_with_transforms` function * It runs! * Added the code for handling p-ed html shortcodes * Removed placeholders in markdown function * Adjusted integration tests * fetch_shortcodes now also returns a string * Start of HTML insertion * Kinda working everything * Loading of shortcodes and builtins * Fix tests * Some missed fixes * Tweaks + fmt * Remove string literal handling * Fix benches * Grab shortcode def only once per site * Fix benches * Rewrite of parser * Fix tests * Add test for #1655 * Re-enable integration test * Add test for #1601 * Add test for #1600 * Add test for #1500 * Add test for #1320 * Fix test on windows? Co-authored-by: Gijs Burghoorn <g.burghoorn@gmail.com>
2021-11-19 19:31:42 +00:00
use rendering::{render_content, RenderContext};
2018-10-31 07:18:57 +00:00
use tera::Tera;
2017-07-04 12:27:32 +00:00
2021-08-18 07:36:51 +00:00
static CONTENT: &str = r#"
2017-07-04 12:27:32 +00:00
# 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.
- :one: Seque vidit flendoque de quodam
- :two: Dabit minimos deiecto caputque noctis pluma
- :three: Leti coniunx est Helicen
- :four: Illius pulvereumque Icare inpositos
- :five: Vivunt pereo pluvio tot ramos Olenios gelidis
- :six: Quater teretes natura inde
2017-07-04 12:27:32 +00:00
### 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! :exclamation:
2017-07-04 12:27:32 +00:00
## 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 :fire:
2017-07-04 12:27:32 +00:00
- 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();
Shortcodes (#1640) * Next version * Added tests for shortcode insertion * Added TOC tests * Added test for #1475 and #1355 * Basic internal / external links tests * Added integration test * Added pseudocode and started on logos * Logos parsing for shortcodes * Fixed string literal parsing Moved string literal parsing to a new lexer in order to have greater control of control characters which are parsed. This fixes the bug that was present in the `string_from_quoted` function and also moves the `QuoteType` to be in the `ArgValueToken`. * Moved string literal logic to seperate module * Added square bracket notation for variables * Error handling rewritten Remove the Result from the `fetch_shortcodes` function. Added proper messages within the internal parsing. * Reorganized and documented the shortcode submodule * Added all logic for ShortcodeContext spans * Added working insertion code for MD files * Made functions generic over Markdown or HTML * Add check for embedding bodies * Structure of main function clear * Added test for `new_with_transforms` function * It runs! * Added the code for handling p-ed html shortcodes * Removed placeholders in markdown function * Adjusted integration tests * fetch_shortcodes now also returns a string * Start of HTML insertion * Kinda working everything * Loading of shortcodes and builtins * Fix tests * Some missed fixes * Tweaks + fmt * Remove string literal handling * Fix benches * Grab shortcode def only once per site * Fix benches * Rewrite of parser * Fix tests * Add test for #1655 * Re-enable integration test * Add test for #1601 * Add test for #1600 * Add test for #1500 * Add test for #1320 * Fix test on windows? Co-authored-by: Gijs Burghoorn <g.burghoorn@gmail.com>
2021-11-19 19:31:42 +00:00
let mut config = Config::default();
config.markdown.highlight_code = true;
2021-08-18 07:36:51 +00:00
let current_page_permalink = "";
let context = RenderContext::new(
&tera,
&config,
Shortcodes (#1640) * Next version * Added tests for shortcode insertion * Added TOC tests * Added test for #1475 and #1355 * Basic internal / external links tests * Added integration test * Added pseudocode and started on logos * Logos parsing for shortcodes * Fixed string literal parsing Moved string literal parsing to a new lexer in order to have greater control of control characters which are parsed. This fixes the bug that was present in the `string_from_quoted` function and also moves the `QuoteType` to be in the `ArgValueToken`. * Moved string literal logic to seperate module * Added square bracket notation for variables * Error handling rewritten Remove the Result from the `fetch_shortcodes` function. Added proper messages within the internal parsing. * Reorganized and documented the shortcode submodule * Added all logic for ShortcodeContext spans * Added working insertion code for MD files * Made functions generic over Markdown or HTML * Add check for embedding bodies * Structure of main function clear * Added test for `new_with_transforms` function * It runs! * Added the code for handling p-ed html shortcodes * Removed placeholders in markdown function * Adjusted integration tests * fetch_shortcodes now also returns a string * Start of HTML insertion * Kinda working everything * Loading of shortcodes and builtins * Fix tests * Some missed fixes * Tweaks + fmt * Remove string literal handling * Fix benches * Grab shortcode def only once per site * Fix benches * Rewrite of parser * Fix tests * Add test for #1655 * Re-enable integration test * Add test for #1601 * Add test for #1600 * Add test for #1500 * Add test for #1320 * Fix test on windows? Co-authored-by: Gijs Burghoorn <g.burghoorn@gmail.com>
2021-11-19 19:31:42 +00:00
&config.default_language,
2021-08-18 07:36:51 +00:00
current_page_permalink,
&permalinks_ctx,
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.markdown.highlight_code = false;
2021-08-18 07:36:51 +00:00
let current_page_permalink = "";
let context = RenderContext::new(
&tera,
&config,
Shortcodes (#1640) * Next version * Added tests for shortcode insertion * Added TOC tests * Added test for #1475 and #1355 * Basic internal / external links tests * Added integration test * Added pseudocode and started on logos * Logos parsing for shortcodes * Fixed string literal parsing Moved string literal parsing to a new lexer in order to have greater control of control characters which are parsed. This fixes the bug that was present in the `string_from_quoted` function and also moves the `QuoteType` to be in the `ArgValueToken`. * Moved string literal logic to seperate module * Added square bracket notation for variables * Error handling rewritten Remove the Result from the `fetch_shortcodes` function. Added proper messages within the internal parsing. * Reorganized and documented the shortcode submodule * Added all logic for ShortcodeContext spans * Added working insertion code for MD files * Made functions generic over Markdown or HTML * Add check for embedding bodies * Structure of main function clear * Added test for `new_with_transforms` function * It runs! * Added the code for handling p-ed html shortcodes * Removed placeholders in markdown function * Adjusted integration tests * fetch_shortcodes now also returns a string * Start of HTML insertion * Kinda working everything * Loading of shortcodes and builtins * Fix tests * Some missed fixes * Tweaks + fmt * Remove string literal handling * Fix benches * Grab shortcode def only once per site * Fix benches * Rewrite of parser * Fix tests * Add test for #1655 * Re-enable integration test * Add test for #1601 * Add test for #1600 * Add test for #1500 * Add test for #1320 * Fix test on windows? Co-authored-by: Gijs Burghoorn <g.burghoorn@gmail.com>
2021-11-19 19:31:42 +00:00
&config.default_language,
2021-08-18 07:36:51 +00:00
current_page_permalink,
&permalinks_ctx,
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
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.markdown.highlight_code = false;
2018-05-06 20:58:39 +00:00
let permalinks_ctx = HashMap::new();
2021-08-18 07:36:51 +00:00
let current_page_permalink = "";
let context = RenderContext::new(
&tera,
&config,
Shortcodes (#1640) * Next version * Added tests for shortcode insertion * Added TOC tests * Added test for #1475 and #1355 * Basic internal / external links tests * Added integration test * Added pseudocode and started on logos * Logos parsing for shortcodes * Fixed string literal parsing Moved string literal parsing to a new lexer in order to have greater control of control characters which are parsed. This fixes the bug that was present in the `string_from_quoted` function and also moves the `QuoteType` to be in the `ArgValueToken`. * Moved string literal logic to seperate module * Added square bracket notation for variables * Error handling rewritten Remove the Result from the `fetch_shortcodes` function. Added proper messages within the internal parsing. * Reorganized and documented the shortcode submodule * Added all logic for ShortcodeContext spans * Added working insertion code for MD files * Made functions generic over Markdown or HTML * Add check for embedding bodies * Structure of main function clear * Added test for `new_with_transforms` function * It runs! * Added the code for handling p-ed html shortcodes * Removed placeholders in markdown function * Adjusted integration tests * fetch_shortcodes now also returns a string * Start of HTML insertion * Kinda working everything * Loading of shortcodes and builtins * Fix tests * Some missed fixes * Tweaks + fmt * Remove string literal handling * Fix benches * Grab shortcode def only once per site * Fix benches * Rewrite of parser * Fix tests * Add test for #1655 * Re-enable integration test * Add test for #1601 * Add test for #1600 * Add test for #1500 * Add test for #1320 * Fix test on windows? Co-authored-by: Gijs Burghoorn <g.burghoorn@gmail.com>
2021-11-19 19:31:42 +00:00
&config.default_language,
2021-08-18 07:36:51 +00:00
current_page_permalink,
&permalinks_ctx,
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]
Shortcodes (#1640) * Next version * Added tests for shortcode insertion * Added TOC tests * Added test for #1475 and #1355 * Basic internal / external links tests * Added integration test * Added pseudocode and started on logos * Logos parsing for shortcodes * Fixed string literal parsing Moved string literal parsing to a new lexer in order to have greater control of control characters which are parsed. This fixes the bug that was present in the `string_from_quoted` function and also moves the `QuoteType` to be in the `ArgValueToken`. * Moved string literal logic to seperate module * Added square bracket notation for variables * Error handling rewritten Remove the Result from the `fetch_shortcodes` function. Added proper messages within the internal parsing. * Reorganized and documented the shortcode submodule * Added all logic for ShortcodeContext spans * Added working insertion code for MD files * Made functions generic over Markdown or HTML * Add check for embedding bodies * Structure of main function clear * Added test for `new_with_transforms` function * It runs! * Added the code for handling p-ed html shortcodes * Removed placeholders in markdown function * Adjusted integration tests * fetch_shortcodes now also returns a string * Start of HTML insertion * Kinda working everything * Loading of shortcodes and builtins * Fix tests * Some missed fixes * Tweaks + fmt * Remove string literal handling * Fix benches * Grab shortcode def only once per site * Fix benches * Rewrite of parser * Fix tests * Add test for #1655 * Re-enable integration test * Add test for #1601 * Add test for #1600 * Add test for #1500 * Add test for #1320 * Fix test on windows? Co-authored-by: Gijs Burghoorn <g.burghoorn@gmail.com>
2021-11-19 19:31:42 +00:00
fn bench_render_content_with_emoji(b: &mut test::Bencher) {
let tera = Tera::default();
let content2 = CONTENT.replace(r#"{{ youtube(id="my_youtube_id") }}"#, "");
let mut config = Config::default();
config.markdown.highlight_code = false;
config.markdown.render_emoji = true;
let permalinks_ctx = HashMap::new();
2021-08-18 07:36:51 +00:00
let current_page_permalink = "";
let context = RenderContext::new(
&tera,
&config,
Shortcodes (#1640) * Next version * Added tests for shortcode insertion * Added TOC tests * Added test for #1475 and #1355 * Basic internal / external links tests * Added integration test * Added pseudocode and started on logos * Logos parsing for shortcodes * Fixed string literal parsing Moved string literal parsing to a new lexer in order to have greater control of control characters which are parsed. This fixes the bug that was present in the `string_from_quoted` function and also moves the `QuoteType` to be in the `ArgValueToken`. * Moved string literal logic to seperate module * Added square bracket notation for variables * Error handling rewritten Remove the Result from the `fetch_shortcodes` function. Added proper messages within the internal parsing. * Reorganized and documented the shortcode submodule * Added all logic for ShortcodeContext spans * Added working insertion code for MD files * Made functions generic over Markdown or HTML * Add check for embedding bodies * Structure of main function clear * Added test for `new_with_transforms` function * It runs! * Added the code for handling p-ed html shortcodes * Removed placeholders in markdown function * Adjusted integration tests * fetch_shortcodes now also returns a string * Start of HTML insertion * Kinda working everything * Loading of shortcodes and builtins * Fix tests * Some missed fixes * Tweaks + fmt * Remove string literal handling * Fix benches * Grab shortcode def only once per site * Fix benches * Rewrite of parser * Fix tests * Add test for #1655 * Re-enable integration test * Add test for #1601 * Add test for #1600 * Add test for #1500 * Add test for #1320 * Fix test on windows? Co-authored-by: Gijs Burghoorn <g.burghoorn@gmail.com>
2021-11-19 19:31:42 +00:00
&config.default_language,
2021-08-18 07:36:51 +00:00
current_page_permalink,
&permalinks_ctx,
InsertAnchor::None,
);
b.iter(|| render_content(&content2, &context).unwrap());
}