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.

67 lines
1.9KB

  1. #![feature(test)]
  2. extern crate test;
  3. extern crate site;
  4. extern crate tempdir;
  5. use std::env;
  6. use tempdir::TempDir;
  7. use site::Site;
  8. fn setup_site(name: &str) -> Site {
  9. let mut path = env::current_dir().unwrap().to_path_buf();
  10. path.push("benches");
  11. path.push(name);
  12. let mut site = Site::new(&path, "config.toml").unwrap();
  13. site.load().unwrap();
  14. site
  15. }
  16. #[bench]
  17. fn bench_render_aliases(b: &mut test::Bencher) {
  18. let mut site = setup_site("huge-blog");
  19. let tmp_dir = TempDir::new("benches").expect("create temp dir");
  20. let public = &tmp_dir.path().join("public");
  21. site.set_output_path(&public);
  22. b.iter(|| site.render_aliases().unwrap());
  23. }
  24. #[bench]
  25. fn bench_render_sitemap(b: &mut test::Bencher) {
  26. let mut site = setup_site("huge-blog");
  27. let tmp_dir = TempDir::new("benches").expect("create temp dir");
  28. let public = &tmp_dir.path().join("public");
  29. site.set_output_path(&public);
  30. b.iter(|| site.render_sitemap().unwrap());
  31. }
  32. #[bench]
  33. fn bench_render_rss_feed(b: &mut test::Bencher) {
  34. let mut site = setup_site("huge-blog");
  35. let tmp_dir = TempDir::new("benches").expect("create temp dir");
  36. let public = &tmp_dir.path().join("public");
  37. site.set_output_path(&public);
  38. b.iter(|| site.render_rss_feed().unwrap());
  39. }
  40. #[bench]
  41. fn bench_render_categories(b: &mut test::Bencher) {
  42. let mut site = setup_site("huge-blog");
  43. let tmp_dir = TempDir::new("benches").expect("create temp dir");
  44. let public = &tmp_dir.path().join("public");
  45. site.set_output_path(&public);
  46. b.iter(|| site.render_categories().unwrap());
  47. }
  48. #[bench]
  49. fn bench_render_paginated(b: &mut test::Bencher) {
  50. let mut site = setup_site("medium-blog");
  51. let tmp_dir = TempDir::new("benches").expect("create temp dir");
  52. let public = &tmp_dir.path().join("public");
  53. site.set_output_path(&public);
  54. let section = site.sections.values().collect::<Vec<_>>()[0];
  55. b.iter(|| site.render_paginated(&public, section));
  56. }