You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.2KB

  1. #![feature(test)]
  2. extern crate test;
  3. extern crate tera;
  4. extern crate rendering;
  5. extern crate config;
  6. extern crate front_matter;
  7. use std::collections::HashMap;
  8. use std::path::Path;
  9. use tera::Tera;
  10. use rendering::{RenderContext, render_content, render_shortcodes};
  11. use front_matter::InsertAnchor;
  12. use config::Config;
  13. static CONTENT: &'static str = r#"
  14. # Modus cognitius profanam ne duae virtutis mundi
  15. ## Ut vita
  16. Lorem markdownum litora, care ponto nomina, et ut aspicit gelidas sui et
  17. purpureo genuit. Tamen colla venientis [delphina](http://nil-sol.com/ecquis)
  18. Tusci et temptata citaeque curam isto ubi vult vulnere reppulit.
  19. - Seque vidit flendoque de quodam
  20. - Dabit minimos deiecto caputque noctis pluma
  21. - Leti coniunx est Helicen
  22. - Illius pulvereumque Icare inpositos
  23. - Vivunt pereo pluvio tot ramos Olenios gelidis
  24. - Quater teretes natura inde
  25. ### A subsection
  26. Protinus dicunt, breve per, et vivacis genus Orphei munere. Me terram [dimittere
  27. casside](http://corpus.org/) pervenit saxo primoque frequentat genuum sorori
  28. praeferre causas Libys. Illud in serpit adsuetam utrimque nunc haberent,
  29. **terrae si** veni! Hectoreis potes sumite [Mavortis retusa](http://tua.org/)
  30. granum captantur potuisse Minervae, frugum.
  31. > Clivo sub inprovisoque nostrum minus fama est, discordia patrem petebat precatur
  32. absumitur, poena per sit. Foramina *tamen cupidine* memor supplex tollentes
  33. dictum unam orbem, Anubis caecae. Viderat formosior tegebat satis, Aethiopasque
  34. sit submisso coniuge tristis ubi!
  35. ## Praeceps Corinthus totidem quem crus vultum cape
  36. ```rs
  37. #[derive(Debug)]
  38. pub struct Site {
  39. /// The base path of the gutenberg site
  40. pub base_path: PathBuf,
  41. /// The parsed config for the site
  42. pub config: Config,
  43. pub pages: HashMap<PathBuf, Page>,
  44. pub sections: HashMap<PathBuf, Section>,
  45. pub tera: Tera,
  46. live_reload: bool,
  47. output_path: PathBuf,
  48. static_path: PathBuf,
  49. pub tags: Option<Taxonomy>,
  50. pub categories: Option<Taxonomy>,
  51. /// A map of all .md files (section and pages) and their permalink
  52. /// We need that if there are relative links in the content that need to be resolved
  53. pub permalinks: HashMap<String, String>,
  54. }
  55. ```
  56. ## More stuff
  57. And a shortcode:
  58. {{ youtube(id="my_youtube_id") }}
  59. ### Another subsection
  60. Gotta make the toc do a little bit of work
  61. # A big title
  62. - hello
  63. - world
  64. - !
  65. ```py
  66. if __name__ == "__main__":
  67. gen_site("basic-blog", [""], 250, paginate=True)
  68. ```
  69. "#;
  70. #[bench]
  71. fn bench_render_content_with_highlighting(b: &mut test::Bencher) {
  72. let mut tera = Tera::default();
  73. tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
  74. let permalinks_ctx = HashMap::new();
  75. let config = Config::default();
  76. let context = RenderContext::new(&tera, &config, "", &permalinks_ctx, Path::new(""), InsertAnchor::None);
  77. b.iter(|| render_content(CONTENT, &context).unwrap());
  78. }
  79. #[bench]
  80. fn bench_render_content_without_highlighting(b: &mut test::Bencher) {
  81. let mut tera = Tera::default();
  82. tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
  83. let permalinks_ctx = HashMap::new();
  84. let mut config = Config::default();
  85. config.highlight_code = false;
  86. let context = RenderContext::new(&tera, &config, "", &permalinks_ctx, Path::new(""), InsertAnchor::None);
  87. b.iter(|| render_content(CONTENT, &context).unwrap());
  88. }
  89. #[bench]
  90. fn bench_render_content_no_shortcode(b: &mut test::Bencher) {
  91. let tera = Tera::default();
  92. let content2 = CONTENT.replace(r#"{{ youtube(id="my_youtube_id") }}"#, "");
  93. let mut config = Config::default();
  94. config.highlight_code = false;
  95. let permalinks_ctx = HashMap::new();
  96. let context = RenderContext::new(&tera, &config, "", &permalinks_ctx, Path::new(""), InsertAnchor::None);
  97. b.iter(|| render_content(&content2, &context).unwrap());
  98. }
  99. #[bench]
  100. fn bench_render_shortcodes_one_present(b: &mut test::Bencher) {
  101. let mut tera = Tera::default();
  102. tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
  103. let config = Config::default();
  104. let permalinks_ctx = HashMap::new();
  105. let context = RenderContext::new(&tera, &config, "", &permalinks_ctx, Path::new(""), InsertAnchor::None);
  106. b.iter(|| render_shortcodes(CONTENT, &context));
  107. }