2019-12-19 14:06:48 +03:00
|
|
|
use std::{path, env};
|
|
|
|
|
|
|
|
/// A module with functions generating huge chunk of texts for text component benchmarks.
|
|
|
|
mod huge_text_generator {
|
|
|
|
use std::collections::hash_map::DefaultHasher;
|
|
|
|
use std::fs::File;
|
|
|
|
use std::hash::{Hash,Hasher};
|
|
|
|
use std::io::Write;
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
const MANY : usize = 100000;
|
|
|
|
const NOT_SO_MANY : usize = 100;
|
|
|
|
|
|
|
|
/// Create a file with many lines.
|
|
|
|
pub fn make_long_text_file(name:&Path) {
|
|
|
|
let mut file = File::create(name).unwrap();
|
|
|
|
for i in (1..MANY).rev() {
|
|
|
|
write_verse(&mut file, i);
|
|
|
|
writeln!(file).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a file with not so many long lines
|
|
|
|
pub fn make_wide_text_file(name:&Path) {
|
|
|
|
let mut file = File::create(name).unwrap();
|
|
|
|
let verses_in_line = MANY/NOT_SO_MANY;
|
|
|
|
for i in (1..MANY).rev() {
|
|
|
|
write_verse(&mut file, i);
|
|
|
|
if i % verses_in_line == 0 {
|
|
|
|
let line_index = i / verses_in_line;
|
|
|
|
let offset = hash_from(line_index) % 32;
|
|
|
|
let prefix = (0..offset).map(|_| '|').collect::<String>();
|
2021-05-20 17:50:43 +03:00
|
|
|
writeln!(file).unwrap();
|
2019-12-24 11:29:10 +03:00
|
|
|
write!(file,"{}",prefix).unwrap();
|
2019-12-19 14:06:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-24 11:29:10 +03:00
|
|
|
fn hash_from(i:usize) -> u64 {
|
2019-12-19 14:06:48 +03:00
|
|
|
let mut hasher = DefaultHasher::new();
|
|
|
|
i.hash(&mut hasher);
|
|
|
|
hasher.finish()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn write_verse(file:&mut File, i:usize) {
|
|
|
|
write!(file,
|
|
|
|
"{i} bottles of beer on the wall, {i} bottles of beer.\
|
|
|
|
Take one down and pass it around, {j} bottles of beer on the wall. ",
|
|
|
|
i = i,
|
|
|
|
j = i-1
|
|
|
|
).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let out = env::var("OUT_DIR").unwrap();
|
|
|
|
let out_dir = path::Path::new(&out);
|
|
|
|
huge_text_generator::make_long_text_file(out_dir.join("long.txt").as_path());
|
|
|
|
huge_text_generator::make_wide_text_file(out_dir.join("wide.txt").as_path());
|
2020-03-17 19:30:43 +03:00
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
2019-12-19 14:06:48 +03:00
|
|
|
}
|