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.

110 lines
3.2KB

  1. #![feature(test)]
  2. extern crate test;
  3. extern crate site;
  4. extern crate library;
  5. extern crate tempfile;
  6. use std::env;
  7. use tempfile::tempdir;
  8. use site::Site;
  9. use library::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("big-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("big-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("big-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(site.library.pages_values(), 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.library.sections_values()[0];
  57. let paginator = Paginator::from_section(&section, &site.library);
  58. b.iter(|| site.render_paginated(public, &paginator));
  59. }
  60. #[bench]
  61. fn bench_populate_sections_medium_blog(b: &mut test::Bencher) {
  62. let mut site = setup_site("medium-blog");
  63. let tmp_dir = tempdir().expect("create temp dir");
  64. let public = &tmp_dir.path().join("public");
  65. site.set_output_path(&public);
  66. b.iter(|| site.populate_sections());
  67. }
  68. #[bench]
  69. fn bench_populate_sections_medium_kb(b: &mut test::Bencher) {
  70. let mut site = setup_site("medium-kb");
  71. let tmp_dir = tempdir().expect("create temp dir");
  72. let public = &tmp_dir.path().join("public");
  73. site.set_output_path(&public);
  74. b.iter(|| site.populate_sections());
  75. }
  76. #[bench]
  77. fn bench_render_markdown_small_blog(b: &mut test::Bencher) {
  78. let mut site = setup_site("small-blog");
  79. let tmp_dir = tempdir().expect("create temp dir");
  80. let public = &tmp_dir.path().join("public");
  81. site.set_output_path(&public);
  82. b.iter(|| site.render_markdown());
  83. }
  84. #[bench]
  85. fn bench_render_markdown_small_kb(b: &mut test::Bencher) {
  86. let mut site = setup_site("small-kb");
  87. let tmp_dir = tempdir().expect("create temp dir");
  88. let public = &tmp_dir.path().join("public");
  89. site.set_output_path(&public);
  90. b.iter(|| site.render_markdown());
  91. }