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
3.9KB

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