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.

104 lines
3.1KB

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