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.

74 lines
2.3KB

  1. //! Benchmarking separate functions of Gutenberg
  2. #![feature(test)]
  3. extern crate test;
  4. extern crate gutenberg;
  5. extern crate tempdir;
  6. use std::env;
  7. use tempdir::TempDir;
  8. use gutenberg::{Site, sort_pages};
  9. fn setup_site(name: &str) -> Site {
  10. let mut path = env::current_dir().unwrap().to_path_buf();
  11. path.push("benches");
  12. path.push(name);
  13. let mut site = Site::new(&path, "config.toml").unwrap();
  14. site.load().unwrap();
  15. site
  16. }
  17. #[bench]
  18. fn bench_render_aliases(b: &mut test::Bencher) {
  19. let mut site = setup_site("huge-blog");
  20. let tmp_dir = TempDir::new("benches").expect("create temp dir");
  21. let public = &tmp_dir.path().join("public");
  22. site.set_output_path(&public);
  23. b.iter(|| site.render_aliases().unwrap());
  24. }
  25. //
  26. //#[bench]
  27. //fn bench_render_sections_one_huge(b: &mut test::Bencher) {
  28. // let mut site = setup_site("big-blog");
  29. // let tmp_dir = TempDir::new("benches").expect("create temp dir");
  30. // let public = &tmp_dir.path().join("public");
  31. // site.set_output_path(&public);
  32. // b.iter(|| site.render_sections().unwrap());
  33. //}
  34. #[bench]
  35. fn bench_render_small_section_with_pages_and_pagination(b: &mut test::Bencher) {
  36. let mut site = setup_site("small-blog");
  37. let tmp_dir = TempDir::new("benches").expect("create temp dir");
  38. let public = &tmp_dir.path().join("public");
  39. site.set_output_path(&public);
  40. b.iter(|| site.render_section(site.sections.values().next().unwrap(), true).unwrap());
  41. }
  42. #[bench]
  43. fn bench_render_small_section_with_pages_and_no_pagination(b: &mut test::Bencher) {
  44. let mut site = setup_site("small-blog");
  45. let tmp_dir = TempDir::new("benches").expect("create temp dir");
  46. let public = &tmp_dir.path().join("public");
  47. site.set_output_path(&public);
  48. let mut section = site.sections.values().next().unwrap().clone();
  49. section.meta.paginate_by = None;
  50. section.meta.template = None;
  51. b.iter(|| site.render_section(&section, true).unwrap());
  52. }
  53. #[bench]
  54. fn bench_sort_sections_pages_medium_blog(b: &mut test::Bencher) {
  55. let mut site = setup_site("medium-blog");
  56. b.iter(|| site.sort_sections_pages(None));
  57. }
  58. #[bench]
  59. fn bench_sort_sections_pages_medium_kb(b: &mut test::Bencher) {
  60. let mut site = setup_site("medium-kb");
  61. b.iter(|| site.sort_sections_pages(None));
  62. }