Bench + parallelize more things
This commit is contained in:
parent
d966a69286
commit
7768a0cc12
68
Cargo.lock
generated
68
Cargo.lock
generated
|
@ -20,9 +20,9 @@ dependencies = [
|
|||
"staticfile 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syntect 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tera 0.10.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tera 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"term-painter 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ws 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -319,12 +319,12 @@ dependencies = [
|
|||
"language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -365,10 +365,10 @@ dependencies = [
|
|||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"modifier 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -580,7 +580,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.6.0"
|
||||
version = "1.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -681,7 +681,7 @@ dependencies = [
|
|||
"futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -698,7 +698,7 @@ dependencies = [
|
|||
"aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thread_local 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thread_local 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -807,7 +807,7 @@ dependencies = [
|
|||
"iron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mount 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -863,10 +863,10 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tera"
|
||||
version = "0.10.7"
|
||||
version = "0.10.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"chrono 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"humansize 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -876,12 +876,12 @@ dependencies = [
|
|||
"serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"slug 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "term"
|
||||
version = "0.4.5"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -893,7 +893,7 @@ name = "term-painter"
|
|||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"term 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -915,22 +915,13 @@ dependencies = [
|
|||
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread-id"
|
||||
version = "3.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "0.3.3"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"thread-id 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -946,7 +937,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.4.1"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1013,7 +1004,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "unreachable"
|
||||
version = "0.1.1"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1029,7 +1020,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "1.5.0"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"idna 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1099,7 +1090,7 @@ dependencies = [
|
|||
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sha1 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1192,7 +1183,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "ef1a4bf6f9174aa5783a9b4cc892cacd11aebad6c69ad027a0b65c6ca5f8aa37"
|
||||
"checksum num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d1891bd7b936f12349b7d1403761c8a0b85a18b148e9da4429d5d102c1a41e"
|
||||
"checksum num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "1708c0628602a98b52fad936cf3edb9a107af06e52e49fdf0707e884456a6af6"
|
||||
"checksum num_cpus 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "83df569ffd47dbf87f36bead512632f89e90882b8e7a14286d0471daf6b72de9"
|
||||
"checksum num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aec53c34f2d0247c5ca5d32cca1478762f301740468ee9ee6dcb7a0dd7a0c584"
|
||||
"checksum onig 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee619da9cf707b167098e84fb00f10db61d5a662d1d29b59822bcac3a81553dd"
|
||||
"checksum onig_sys 63.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "531682ab45a2cd40eff91f29340dae975f25336d2b61e624adabed39e61d7fb3"
|
||||
"checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356"
|
||||
|
@ -1228,15 +1219,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
|
||||
"checksum syntect 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f75613d1df82e2f8020e86c260a46bdef180d16ac8d2febe43194037d6fe76"
|
||||
"checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6"
|
||||
"checksum tera 0.10.7 (registry+https://github.com/rust-lang/crates.io-index)" = "4135ff32e097c0878e64d3a94d73a8af3d0b300928c1f1e5781cde1c436088a3"
|
||||
"checksum term 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d168af3930b369cfe245132550579d47dfd873d69470755a19c2c6568dbbd989"
|
||||
"checksum tera 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)" = "62736a6d748fd2c5a8b4be21010e37d79f78aea3c2e07a9e13ff5c70864a3129"
|
||||
"checksum term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "fa63644f74ce96fbeb9b794f66aff2a52d601cbd5e80f4b97123e3899f4570f1"
|
||||
"checksum term-painter 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ab900bf2f05175932b13d4fc12f8ff09ef777715b04998791ab2c930841e496b"
|
||||
"checksum term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2b6b55df3198cc93372e85dd2ed817f0e38ce8cc0f22eb32391bfad9c4bf209"
|
||||
"checksum textwrap 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f86300c3e7416ee233abd7cda890c492007a3980f941f79185c753a701257167"
|
||||
"checksum thread-id 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8df7875b676fddfadffd96deea3b1124e5ede707d4884248931077518cf1f773"
|
||||
"checksum thread_local 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c85048c6260d17cf486ceae3282d9fb6b90be220bf5b28c400f5485ffc29f0c7"
|
||||
"checksum thread_local 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1697c4b57aeeb7a536b647165a2825faddffb1d3bad386d507709bd51a90bb14"
|
||||
"checksum time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "ffd7ccbf969a892bf83f1e441126968a07a3941c24ff522a26af9f9f4585d1a3"
|
||||
"checksum toml 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4cc5dbfb20a481e64b99eb7ae280859ec76730c7191570ba5edaa962394edb0a"
|
||||
"checksum toml 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b0601da6c97135c8d330c7a13a013ca6cd4143221b01de2f8d4edc50a9e551c7"
|
||||
"checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079"
|
||||
"checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887"
|
||||
"checksum typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "653be63c80a3296da5551e1bfd2cca35227e13cdd08c6668903ae2f4f77aa1f6"
|
||||
|
@ -1247,9 +1237,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f"
|
||||
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
|
||||
"checksum unidecode 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2adb95ee07cd579ed18131f2d9e7a17c25a4b76022935c7f2460d2bfae89fd2"
|
||||
"checksum unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2ae5ddb18e1c92664717616dd9549dde73f539f01bd7b77c2edb2446bdff91"
|
||||
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
|
||||
"checksum unsafe-any 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f30360d7979f5e9c6e6cea48af192ea8fab4afb3cf72597154b8f08935bc9c7f"
|
||||
"checksum url 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a69a2e36a5e5ed3f3063c8c64a3b028c4d50d689fa6c862abd7cfe65f882595c"
|
||||
"checksum url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb819346883532a271eb626deb43c4a1bb4c4dd47c519bd78137c3e72a4fe27"
|
||||
"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
|
||||
"checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c"
|
||||
"checksum version_check 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2bb3950bf29e36796dea723df1747619dd331881aefef75b7cf1c58fdd738afe"
|
||||
|
|
83
benches/site_render.rs
Normal file
83
benches/site_render.rs
Normal file
|
@ -0,0 +1,83 @@
|
|||
//! Benchmarking writing down on the hard drive sites of various sizes
|
||||
|
||||
#![feature(test)]
|
||||
extern crate test;
|
||||
extern crate gutenberg;
|
||||
extern crate tempdir;
|
||||
|
||||
use std::env;
|
||||
|
||||
use gutenberg::Site;
|
||||
use tempdir::TempDir;
|
||||
|
||||
|
||||
#[bench]
|
||||
fn bench_rendering_small_blog(b: &mut test::Bencher) {
|
||||
let mut path = env::current_dir().unwrap().to_path_buf();
|
||||
path.push("benches");
|
||||
path.push("small-blog");
|
||||
let mut site = Site::new(&path, "config.toml").unwrap();
|
||||
let tmp_dir = TempDir::new("example").expect("create temp dir");
|
||||
let public = &tmp_dir.path().join("public");
|
||||
site.set_output_path(&public);
|
||||
site.load().unwrap();
|
||||
|
||||
b.iter(|| site.build().unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_rendering_medium_blog(b: &mut test::Bencher) {
|
||||
let mut path = env::current_dir().unwrap().to_path_buf();
|
||||
path.push("benches");
|
||||
path.push("medium-blog");
|
||||
let mut site = Site::new(&path, "config.toml").unwrap();
|
||||
let tmp_dir = TempDir::new("example").expect("create temp dir");
|
||||
let public = &tmp_dir.path().join("public");
|
||||
site.set_output_path(&public);
|
||||
site.load().unwrap();
|
||||
|
||||
b.iter(|| site.build().unwrap());
|
||||
}
|
||||
|
||||
//#[bench]
|
||||
//fn bench_rendering_big_blog(b: &mut test::Bencher) {
|
||||
// let mut path = env::current_dir().unwrap().to_path_buf();
|
||||
// path.push("benches");
|
||||
// path.push("big-blog");
|
||||
// let mut site = Site::new(&path, "config.toml").unwrap();
|
||||
// let tmp_dir = TempDir::new("example").expect("create temp dir");
|
||||
// let public = &tmp_dir.path().join("public");
|
||||
// site.set_output_path(&public);
|
||||
// site.load().unwrap();
|
||||
//
|
||||
// b.iter(|| site.build().unwrap());
|
||||
//}
|
||||
|
||||
#[bench]
|
||||
fn bench_rendering_small_kb(b: &mut test::Bencher) {
|
||||
let mut path = env::current_dir().unwrap().to_path_buf();
|
||||
path.push("benches");
|
||||
path.push("small-kb");
|
||||
let mut site = Site::new(&path, "config.toml").unwrap();
|
||||
let tmp_dir = TempDir::new("example").expect("create temp dir");
|
||||
let public = &tmp_dir.path().join("public");
|
||||
site.set_output_path(&public);
|
||||
site.load().unwrap();
|
||||
|
||||
b.iter(|| site.build().unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_rendering_medium_kb(b: &mut test::Bencher) {
|
||||
let mut path = env::current_dir().unwrap().to_path_buf();
|
||||
path.push("benches");
|
||||
path.push("medium-kb");
|
||||
let mut site = Site::new(&path, "config.toml").unwrap();
|
||||
let tmp_dir = TempDir::new("example").expect("create temp dir");
|
||||
let public = &tmp_dir.path().join("public");
|
||||
site.set_output_path(&public);
|
||||
site.load().unwrap();
|
||||
|
||||
b.iter(|| site.build().unwrap());
|
||||
}
|
||||
|
60
benches/unit.rs
Normal file
60
benches/unit.rs
Normal file
|
@ -0,0 +1,60 @@
|
|||
//! Benchmarking separate functions of Gutenberg
|
||||
|
||||
#![feature(test)]
|
||||
extern crate test;
|
||||
extern crate gutenberg;
|
||||
extern crate tempdir;
|
||||
|
||||
use std::env;
|
||||
|
||||
use tempdir::TempDir;
|
||||
use gutenberg::Site;
|
||||
|
||||
|
||||
fn setup_site(name: &str) -> Site {
|
||||
let mut path = env::current_dir().unwrap().to_path_buf();
|
||||
path.push("benches");
|
||||
path.push(name);
|
||||
let mut site = Site::new(&path, "config.toml").unwrap();
|
||||
site.load().unwrap();
|
||||
site
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_render_aliases(b: &mut test::Bencher) {
|
||||
let mut site = setup_site("huge-blog");
|
||||
let tmp_dir = TempDir::new("benches").expect("create temp dir");
|
||||
let public = &tmp_dir.path().join("public");
|
||||
site.set_output_path(&public);
|
||||
b.iter(|| site.render_aliases().unwrap());
|
||||
}
|
||||
//
|
||||
//#[bench]
|
||||
//fn bench_render_sections_one_huge(b: &mut test::Bencher) {
|
||||
// let mut site = setup_site("big-blog");
|
||||
// let tmp_dir = TempDir::new("benches").expect("create temp dir");
|
||||
// let public = &tmp_dir.path().join("public");
|
||||
// site.set_output_path(&public);
|
||||
// b.iter(|| site.render_sections().unwrap());
|
||||
//}
|
||||
|
||||
#[bench]
|
||||
fn bench_render_small_section_with_pages_and_pagination(b: &mut test::Bencher) {
|
||||
let mut site = setup_site("small-blog");
|
||||
let tmp_dir = TempDir::new("benches").expect("create temp dir");
|
||||
let public = &tmp_dir.path().join("public");
|
||||
site.set_output_path(&public);
|
||||
b.iter(|| site.render_section(site.sections.values().next().unwrap(), true).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_render_small_section_with_pages_and_no_pagination(b: &mut test::Bencher) {
|
||||
let mut site = setup_site("small-blog");
|
||||
let tmp_dir = TempDir::new("benches").expect("create temp dir");
|
||||
let public = &tmp_dir.path().join("public");
|
||||
site.set_output_path(&public);
|
||||
let mut section = site.sections.values().next().unwrap().clone();
|
||||
section.meta.paginate_by = None;
|
||||
section.meta.template = None;
|
||||
b.iter(|| site.render_section(§ion, true).unwrap());
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
use std::io::prelude::*;
|
||||
use std::fs::{File, create_dir};
|
||||
use std::fs::{File, create_dir_all};
|
||||
use std::path::Path;
|
||||
|
||||
use errors::{Result, ResultExt};
|
||||
|
@ -23,7 +23,7 @@ pub fn ensure_directory_exists(path: &Path) -> Result<()> {
|
|||
/// exists before creating it
|
||||
pub fn create_directory(path: &Path) -> Result<()> {
|
||||
if !path.exists() {
|
||||
create_dir(path)
|
||||
create_dir_all(path)
|
||||
.chain_err(|| format!("Was not able to create folder {}", path.display()))?;
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -34,4 +34,4 @@ pub use site::{Site};
|
|||
pub use config::{Config, get_config};
|
||||
pub use front_matter::{PageFrontMatter, SectionFrontMatter, InsertAnchor, split_page_content, split_section_content};
|
||||
pub use content::{Page, Section, SortBy, sort_pages, populate_previous_and_next_pages};
|
||||
pub use fs::{create_file};
|
||||
pub use fs::{create_file, ensure_directory_exists};
|
||||
|
|
68
src/site.rs
68
src/site.rs
|
@ -131,10 +131,6 @@ impl Site {
|
|||
let s = section?;
|
||||
self.add_section(s, false)?;
|
||||
}
|
||||
for page in pages {
|
||||
let p = page?;
|
||||
self.add_page(p, false)?;
|
||||
}
|
||||
|
||||
// Insert a default index section if necessary so we don't need to create
|
||||
// a _index.md to render the index page
|
||||
|
@ -142,13 +138,15 @@ impl Site {
|
|||
if !self.sections.contains_key(&index_path) {
|
||||
let mut index_section = Section::default();
|
||||
index_section.permalink = self.config.make_permalink("");
|
||||
// TODO: need to insert into permalinks too
|
||||
self.sections.insert(index_path, index_section);
|
||||
}
|
||||
|
||||
// Silly thing needed to make the borrow checker happy
|
||||
let mut pages_insert_anchors = HashMap::new();
|
||||
for page in self.pages.values() {
|
||||
pages_insert_anchors.insert(page.file.path.clone(), self.find_parent_section_insert_anchor(&page.file.parent.clone()));
|
||||
for page in pages {
|
||||
let p = page?;
|
||||
pages_insert_anchors.insert(p.file.path.clone(), self.find_parent_section_insert_anchor(&p.file.parent.clone()));
|
||||
self.add_page(p, false)?;
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -387,6 +385,7 @@ impl Site {
|
|||
self.render_aliases()?;
|
||||
self.render_sections()?;
|
||||
self.render_orphan_pages()?;
|
||||
// TODO: render_sitemap is slow
|
||||
self.render_sitemap()?;
|
||||
if self.config.generate_rss.unwrap() {
|
||||
self.render_rss_feed()?;
|
||||
|
@ -569,9 +568,12 @@ impl Site {
|
|||
}
|
||||
|
||||
if render_pages {
|
||||
for page in §ion.pages {
|
||||
self.render_page(page, Some(section))?;
|
||||
}
|
||||
section
|
||||
.pages
|
||||
.par_iter()
|
||||
.map(|p| self.render_page(&p, Some(section)))
|
||||
.fold(|| Ok(()), Result::and)
|
||||
.reduce(|| Ok(()), Result::and)?;
|
||||
}
|
||||
|
||||
if !section.meta.should_render() {
|
||||
|
@ -598,10 +600,13 @@ impl Site {
|
|||
|
||||
/// Renders all sections
|
||||
pub fn render_sections(&self) -> Result<()> {
|
||||
for section in self.sections.values() {
|
||||
self.render_section(section, true)?;
|
||||
}
|
||||
Ok(())
|
||||
self.sections
|
||||
.values()
|
||||
.collect::<Vec<_>>()
|
||||
.into_par_iter()
|
||||
.map(|s| self.render_section(s, true))
|
||||
.fold(|| Ok(()), Result::and)
|
||||
.reduce(|| Ok(()), Result::and)
|
||||
}
|
||||
|
||||
/// Renders all pages that do not belong to any sections
|
||||
|
@ -625,21 +630,26 @@ impl Site {
|
|||
};
|
||||
|
||||
let paginator = Paginator::new(§ion.pages, section);
|
||||
for (i, pager) in paginator.pagers.iter().enumerate() {
|
||||
let folder_path = output_path.join(&paginate_path);
|
||||
let page_path = folder_path.join(&format!("{}", i + 1));
|
||||
create_directory(&folder_path)?;
|
||||
create_directory(&page_path)?;
|
||||
let output = paginator.render_pager(pager, self)?;
|
||||
if i > 0 {
|
||||
create_file(&page_path.join("index.html"), &self.inject_livereload(output))?;
|
||||
} else {
|
||||
create_file(&output_path.join("index.html"), &self.inject_livereload(output))?;
|
||||
create_file(&page_path.join("index.html"), &render_redirect_template(§ion.permalink, &self.tera)?)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
let folder_path = output_path.join(&paginate_path);
|
||||
create_directory(&folder_path)?;
|
||||
paginator
|
||||
.pagers
|
||||
.par_iter()
|
||||
.enumerate()
|
||||
.map(|(i, pager)| {
|
||||
let page_path = folder_path.join(&format!("{}", i + 1));
|
||||
create_directory(&page_path)?;
|
||||
let output = paginator.render_pager(pager, self)?;
|
||||
if i > 0 {
|
||||
create_file(&page_path.join("index.html"), &self.inject_livereload(output))?;
|
||||
} else {
|
||||
create_file(&output_path.join("index.html"), &self.inject_livereload(output))?;
|
||||
create_file(&page_path.join("index.html"), &render_redirect_template(§ion.permalink, &self.tera)?)?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.fold(|| Ok(()), Result::and)
|
||||
.reduce(|| Ok(()), Result::and)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue