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.

130 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 =
  72. RenderContext::new(&tera, &config, "", &permalinks_ctx, InsertAnchor::None);
  73. b.iter(|| render_content(CONTENT, &context).unwrap());
  74. }
  75. #[bench]
  76. fn bench_render_content_without_highlighting(b: &mut test::Bencher) {
  77. let mut tera = Tera::default();
  78. tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
  79. let permalinks_ctx = HashMap::new();
  80. let mut config = Config::default();
  81. config.highlight_code = false;
  82. let context =
  83. RenderContext::new(&tera, &config, "", &permalinks_ctx, InsertAnchor::None);
  84. b.iter(|| render_content(CONTENT, &context).unwrap());
  85. }
  86. #[bench]
  87. fn bench_render_content_no_shortcode(b: &mut test::Bencher) {
  88. let tera = Tera::default();
  89. let content2 = CONTENT.replace(r#"{{ youtube(id="my_youtube_id") }}"#, "");
  90. let mut config = Config::default();
  91. config.highlight_code = false;
  92. let permalinks_ctx = HashMap::new();
  93. let context =
  94. RenderContext::new(&tera, &config, "", &permalinks_ctx, InsertAnchor::None);
  95. b.iter(|| render_content(&content2, &context).unwrap());
  96. }
  97. #[bench]
  98. fn bench_render_shortcodes_one_present(b: &mut test::Bencher) {
  99. let mut tera = Tera::default();
  100. tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
  101. let config = Config::default();
  102. let permalinks_ctx = HashMap::new();
  103. let context =
  104. RenderContext::new(&tera, &config, "", &permalinks_ctx, InsertAnchor::None);
  105. b.iter(|| render_shortcodes(CONTENT, &context));
  106. }