Created
June 21, 2021 03:23
-
-
Save stepancheg/d9d98be10e1676fd7587a9db81ef5c6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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