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.

126 lines
4.0KB

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