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.

site.rs 3.2KB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
5 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #![feature(test)]
  2. extern crate library;
  3. extern crate site;
  4. extern crate tempfile;
  5. extern crate test;
  6. use std::env;
  7. use library::Paginator;
  8. use site::Site;
  9. use tempfile::tempdir;
  10. fn setup_site(name: &str) -> Site {
  11. let mut path = env::current_dir().unwrap().to_path_buf();
  12. path.push("benches");
  13. path.push(name);
  14. let mut site = Site::new(&path, "config.toml").unwrap();
  15. site.load().unwrap();
  16. site
  17. }
  18. #[bench]
  19. fn bench_render_aliases(b: &mut test::Bencher) {
  20. let mut site = setup_site("big-blog");
  21. let tmp_dir = tempdir().expect("create temp dir");
  22. let public = &tmp_dir.path().join("public");
  23. site.set_output_path(&public);
  24. b.iter(|| site.render_aliases().unwrap());
  25. }
  26. #[bench]
  27. fn bench_render_sitemap(b: &mut test::Bencher) {
  28. let mut site = setup_site("big-blog");
  29. let tmp_dir = tempdir().expect("create temp dir");
  30. let public = &tmp_dir.path().join("public");
  31. site.set_output_path(&public);
  32. b.iter(|| site.render_sitemap().unwrap());
  33. }
  34. #[bench]
  35. fn bench_render_rss_feed(b: &mut test::Bencher) {
  36. let mut site = setup_site("big-blog");
  37. let tmp_dir = tempdir().expect("create temp dir");
  38. let public = &tmp_dir.path().join("public");
  39. site.set_output_path(&public);
  40. b.iter(|| site.render_rss_feed(site.library.read().unwrap().pages_values(), None).unwrap());
  41. }
  42. #[bench]
  43. fn bench_render_taxonomies(b: &mut test::Bencher) {
  44. let mut site = setup_site("small-blog");
  45. let tmp_dir = tempdir().expect("create temp dir");
  46. let public = &tmp_dir.path().join("public");
  47. site.set_output_path(&public);
  48. b.iter(|| site.render_taxonomies().unwrap());
  49. }
  50. #[bench]
  51. fn bench_render_paginated(b: &mut test::Bencher) {
  52. let mut site = setup_site("small-blog");
  53. let tmp_dir = tempdir().expect("create temp dir");
  54. let public = &tmp_dir.path().join("public");
  55. site.set_output_path(&public);
  56. let library = site.library.read().unwrap();
  57. let section = library.sections_values()[0];
  58. let paginator = Paginator::from_section(&section, &library);
  59. b.iter(|| site.render_paginated(public, &paginator));
  60. }
  61. #[bench]
  62. fn bench_populate_sections_medium_blog(b: &mut test::Bencher) {
  63. let mut site = setup_site("medium-blog");
  64. let tmp_dir = tempdir().expect("create temp dir");
  65. let public = &tmp_dir.path().join("public");
  66. site.set_output_path(&public);
  67. b.iter(|| site.populate_sections());
  68. }
  69. #[bench]
  70. fn bench_populate_sections_medium_kb(b: &mut test::Bencher) {
  71. let mut site = setup_site("medium-kb");
  72. let tmp_dir = tempdir().expect("create temp dir");
  73. let public = &tmp_dir.path().join("public");
  74. site.set_output_path(&public);
  75. b.iter(|| site.populate_sections());
  76. }
  77. #[bench]
  78. fn bench_render_markdown_small_blog(b: &mut test::Bencher) {
  79. let mut site = setup_site("small-blog");
  80. let tmp_dir = tempdir().expect("create temp dir");
  81. let public = &tmp_dir.path().join("public");
  82. site.set_output_path(&public);
  83. b.iter(|| site.render_markdown());
  84. }
  85. #[bench]
  86. fn bench_render_markdown_small_kb(b: &mut test::Bencher) {
  87. let mut site = setup_site("small-kb");
  88. let tmp_dir = tempdir().expect("create temp dir");
  89. let public = &tmp_dir.path().join("public");
  90. site.set_output_path(&public);
  91. b.iter(|| site.render_markdown());
  92. }