2019-04-20 13:37:14 +03:00
|
|
|
#![feature(test)]
|
2021-06-29 11:41:12 +03:00
|
|
|
#![allow(clippy::unit_arg)]
|
2019-04-20 13:37:14 +03:00
|
|
|
extern crate test;
|
|
|
|
|
2021-06-29 11:41:12 +03:00
|
|
|
use grcov::{Gcno, GcovReaderBuf, LittleEndian};
|
2019-04-20 13:37:14 +03:00
|
|
|
use std::path::PathBuf;
|
|
|
|
use test::{black_box, Bencher};
|
|
|
|
|
2021-06-29 11:41:12 +03:00
|
|
|
const LLVM_READER_GCNO: &[u8] = include_bytes!("../test/llvm/reader.gcno");
|
|
|
|
const LLVM_READER_GCDA: &[u8] = include_bytes!("../test/llvm/reader.gcda");
|
|
|
|
|
2019-04-20 13:37:14 +03:00
|
|
|
#[bench]
|
|
|
|
fn bench_reader_gcno(b: &mut Bencher) {
|
2021-06-29 11:41:12 +03:00
|
|
|
let mut gcno = Gcno::new();
|
2019-04-20 13:37:14 +03:00
|
|
|
b.iter(|| {
|
2021-06-29 11:41:12 +03:00
|
|
|
let file = GcovReaderBuf::<LittleEndian>::new("reader", LLVM_READER_GCNO.to_vec());
|
|
|
|
black_box(gcno.read_gcno(file).unwrap());
|
2019-04-20 13:37:14 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_reader_gcda(b: &mut Bencher) {
|
2021-06-29 11:41:12 +03:00
|
|
|
let mut gcno = Gcno::new();
|
|
|
|
gcno.read_gcno(GcovReaderBuf::<LittleEndian>::new(
|
|
|
|
"reader",
|
|
|
|
LLVM_READER_GCNO.to_vec(),
|
|
|
|
))
|
|
|
|
.unwrap();
|
2019-04-20 13:37:14 +03:00
|
|
|
|
|
|
|
b.iter(|| {
|
2021-06-29 11:41:12 +03:00
|
|
|
let file = GcovReaderBuf::<LittleEndian>::new("reader", LLVM_READER_GCDA.to_vec());
|
2019-04-20 13:37:14 +03:00
|
|
|
black_box(gcno.read_gcda(file).unwrap());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_reader_gcno_dump(b: &mut Bencher) {
|
2021-06-29 11:41:12 +03:00
|
|
|
let mut gcno = Gcno::new();
|
|
|
|
gcno.read_gcno(GcovReaderBuf::<LittleEndian>::new(
|
|
|
|
"reader",
|
|
|
|
LLVM_READER_GCNO.to_vec(),
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
|
2019-04-20 13:37:14 +03:00
|
|
|
b.iter(|| {
|
|
|
|
let mut output = Vec::new();
|
|
|
|
black_box(
|
|
|
|
gcno.dump(
|
|
|
|
&PathBuf::from("test/llvm/reader.c"),
|
|
|
|
"reader.c",
|
|
|
|
&mut output,
|
|
|
|
)
|
|
|
|
.unwrap(),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_reader_gcno_gcda_dump(b: &mut Bencher) {
|
2021-06-29 11:41:12 +03:00
|
|
|
let mut gcno = Gcno::new();
|
|
|
|
gcno.read_gcno(GcovReaderBuf::<LittleEndian>::new(
|
|
|
|
"reader",
|
|
|
|
LLVM_READER_GCNO.to_vec(),
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
gcno.read_gcda(GcovReaderBuf::<LittleEndian>::new(
|
|
|
|
"reader",
|
|
|
|
LLVM_READER_GCDA.to_vec(),
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
|
2019-04-20 13:37:14 +03:00
|
|
|
b.iter(|| {
|
|
|
|
let mut output = Vec::new();
|
|
|
|
black_box(
|
|
|
|
gcno.dump(
|
|
|
|
&PathBuf::from("test/llvm/reader.c"),
|
|
|
|
"reader.c",
|
|
|
|
&mut output,
|
|
|
|
)
|
|
|
|
.unwrap(),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_reader_finalize_file(b: &mut Bencher) {
|
2021-06-29 11:41:12 +03:00
|
|
|
let mut gcno = Gcno::new();
|
|
|
|
gcno.read_gcno(GcovReaderBuf::<LittleEndian>::new(
|
|
|
|
"reader",
|
|
|
|
LLVM_READER_GCNO.to_vec(),
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
gcno.read_gcda(GcovReaderBuf::<LittleEndian>::new(
|
|
|
|
"reader",
|
|
|
|
LLVM_READER_GCDA.to_vec(),
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
|
2019-04-20 13:37:14 +03:00
|
|
|
b.iter(|| black_box(gcno.finalize(true)));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_reader_finalize_file_branch(b: &mut Bencher) {
|
2021-06-29 11:41:12 +03:00
|
|
|
let mut gcno = Gcno::new();
|
|
|
|
gcno.read_gcno(GcovReaderBuf::<LittleEndian>::new(
|
|
|
|
"reader",
|
|
|
|
LLVM_READER_GCNO.to_vec(),
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
gcno.read_gcda(GcovReaderBuf::<LittleEndian>::new(
|
|
|
|
"reader",
|
|
|
|
LLVM_READER_GCDA.to_vec(),
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
|
2019-04-20 13:37:14 +03:00
|
|
|
b.iter(|| black_box(gcno.finalize(true)));
|
|
|
|
}
|