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.

49 lines
1.3KB

  1. #![feature(test)]
  2. extern crate test;
  3. extern crate gutenberg;
  4. extern crate tempdir;
  5. use std::env;
  6. use tempdir::TempDir;
  7. use gutenberg::{Site, populate_previous_and_next_pages};
  8. // TODO: add bench with ~1000 pages for all cases
  9. #[bench]
  10. fn bench_loading_test_site(b: &mut test::Bencher) {
  11. let mut path = env::current_dir().unwrap().to_path_buf();
  12. path.push("test_site");
  13. let mut site = Site::new(&path, "config.toml").unwrap();
  14. b.iter(|| site.load().unwrap());
  15. }
  16. #[bench]
  17. fn bench_building_test_site(b: &mut test::Bencher) {
  18. let mut path = env::current_dir().unwrap().to_path_buf();
  19. path.push("test_site");
  20. let mut site = Site::new(&path, "config.toml").unwrap();
  21. site.load().unwrap();
  22. let tmp_dir = TempDir::new("example").expect("create temp dir");
  23. let public = &tmp_dir.path().join("public");
  24. site.set_output_path(&public);
  25. b.iter(|| site.build().unwrap());
  26. }
  27. #[bench]
  28. fn bench_populate_previous_and_next_pages(b: &mut test::Bencher) {
  29. let mut path = env::current_dir().unwrap().to_path_buf();
  30. path.push("test_site");
  31. let mut site = Site::new(&path, "config.toml").unwrap();
  32. site.load().unwrap();
  33. let mut pages = site.pages.values().cloned().collect::<Vec<_>>();
  34. pages.sort_by(|a, b| a.partial_cmp(b).unwrap());
  35. b.iter(|| populate_previous_and_next_pages(pages.as_slice()));
  36. }