Skip to content

Instantly share code, notes, and snippets.

@stepancheg
Created June 21, 2021 03:23
Show Gist options
  • Save stepancheg/d9d98be10e1676fd7587a9db81ef5c6e to your computer and use it in GitHub Desktop.
Save stepancheg/d9d98be10e1676fd7587a9db81ef5c6e to your computer and use it in GitHub Desktop.
#![feature(test)]
extern crate test;
use std::fs::File;
use std::io::{BufReader, BufRead};
#[bench]
fn scan_for_generated(bencher: &mut test::Bencher) {
let mut large_file = String::new();
for _ in 0..1000 {
large_file.push_str("0123456789");
}
bencher.iter(|| {
assert!(!test::black_box(&large_file).contains("@generated"));
})
}
#[bench]
fn read_first_line(bencher: &mut test::Bencher) {
bencher.iter(|| {
let mut line = String::new();
BufReader::new(File::open(file!()).unwrap()).read_line(&mut line).unwrap();
assert!(!line.contains("@generated"));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment