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.

unit.rs 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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;
  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. }