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.

136 lines
4.2KB

  1. #![feature(test)]
  2. extern crate tera;
  3. extern crate test;
  4. extern crate config;
  5. extern crate front_matter;
  6. extern crate rendering;
  7. use std::collections::HashMap;
  8. use std::path::Path;
  9. use config::Config;
  10. use front_matter::InsertAnchor;
  11. use rendering::{render_content, render_shortcodes, RenderContext};
  12. use tera::Tera;
  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 =
  77. RenderContext::new(&tera, &config, "", &permalinks_ctx, Path::new(""), InsertAnchor::None);
  78. b.iter(|| render_content(CONTENT, &context).unwrap());
  79. }
  80. #[bench]
  81. fn bench_render_content_without_highlighting(b: &mut test::Bencher) {
  82. let mut tera = Tera::default();
  83. tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
  84. let permalinks_ctx = HashMap::new();
  85. let mut config = Config::default();
  86. config.highlight_code = false;
  87. let context =
  88. RenderContext::new(&tera, &config, "", &permalinks_ctx, Path::new(""), InsertAnchor::None);
  89. b.iter(|| render_content(CONTENT, &context).unwrap());
  90. }
  91. #[bench]
  92. fn bench_render_content_no_shortcode(b: &mut test::Bencher) {
  93. let tera = Tera::default();
  94. let content2 = CONTENT.replace(r#"{{ youtube(id="my_youtube_id") }}"#, "");
  95. let mut config = Config::default();
  96. config.highlight_code = false;
  97. let permalinks_ctx = HashMap::new();
  98. let context =
  99. RenderContext::new(&tera, &config, "", &permalinks_ctx, Path::new(""), InsertAnchor::None);
  100. b.iter(|| render_content(&content2, &context).unwrap());
  101. }
  102. #[bench]
  103. fn bench_render_shortcodes_one_present(b: &mut test::Bencher) {
  104. let mut tera = Tera::default();
  105. tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
  106. let config = Config::default();
  107. let permalinks_ctx = HashMap::new();
  108. let context =
  109. RenderContext::new(&tera, &config, "", &permalinks_ctx, Path::new(""), InsertAnchor::None);
  110. b.iter(|| render_shortcodes(CONTENT, &context));
  111. }