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.

147 lines
4.2KB

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