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.

70 lines
2.0KB

  1. #![feature(test)]
  2. extern crate test;
  3. extern crate site;
  4. extern crate pagination;
  5. extern crate tempfile;
  6. use std::env;
  7. use tempfile::tempdir;
  8. use site::Site;
  9. use pagination::Paginator;
  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("small-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("small-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("small-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(None, 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 section = site.sections.values().collect::<Vec<_>>()[0];
  57. let paginator = Paginator::from_section(&section.pages, section);
  58. b.iter(|| site.render_paginated(public, &paginator));
  59. }