Skip to content

Commit 3a45607

Browse files
committed
wip: benchmarking
1 parent 8da2cb4 commit 3a45607

File tree

6 files changed

+37
-10
lines changed

6 files changed

+37
-10
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ code input cli.
1515
name = "ci"
1616
path = "src/main.rs"
1717

18+
[[bench]]
19+
name = "parser_bench"
20+
path = "src/benches/parser_bench.rs"
21+
harness = false
22+
1823
[features]
1924
nightly = []
2025
termlog = ["slog-term"]
@@ -55,6 +60,7 @@ features = ["cargo", "derive"]
5560
assert_cmd = "2.0.17"
5661
predicates = "3.1.3"
5762
tempfile = "3.20"
63+
criterion = { version = "0.6.0", features = ["html_reports"] }
5864

5965
[profile.dev]
6066
opt-level = 0

src/benches/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub(crate) mod parser_bench;

src/benches/parser_bench.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use codeinput::core::parser::parse_line;
2+
use criterion::{Criterion, black_box, criterion_group, criterion_main};
3+
use std::path::Path;
4+
5+
fn bench_parse_line_simple(c: &mut Criterion) {
6+
let source_path = Path::new("/test/CODEOWNERS");
7+
8+
c.bench_function("parse_line_simple", |b| {
9+
b.iter(|| {
10+
parse_line(
11+
black_box("*.js @user"),
12+
black_box(1),
13+
black_box(source_path),
14+
)
15+
})
16+
});
17+
}
18+
19+
criterion_group!(benches, bench_parse_line_simple);
20+
criterion_main!(benches);

src/core/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
pub mod cache;
2-
pub mod commands;
3-
pub mod common;
4-
pub mod parse;
1+
pub(crate) mod cache;
2+
pub(crate) mod commands;
3+
pub(crate) mod common;
4+
pub(crate) mod parse;
55
pub mod parser;
6-
pub mod resolver;
7-
pub mod types;
6+
pub(crate) mod resolver;
7+
pub(crate) mod types;
88

99
use crate::utils::error::Result;
1010

src/core/parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::path::Path;
44
use super::types::{CodeownersEntry, Owner, OwnerType, Tag};
55

66
/// Parse CODEOWNERS
7-
pub fn parse_codeowners(source_path: &Path) -> Result<Vec<CodeownersEntry>> {
7+
pub(crate) fn parse_codeowners(source_path: &Path) -> Result<Vec<CodeownersEntry>> {
88
let content = std::fs::read_to_string(source_path)?;
99

1010
content
@@ -15,7 +15,7 @@ pub fn parse_codeowners(source_path: &Path) -> Result<Vec<CodeownersEntry>> {
1515
}
1616

1717
/// Parse a line of CODEOWNERS
18-
pub(crate) fn parse_line(
18+
pub fn parse_line(
1919
line: &str, line_num: usize, source_path: &Path,
2020
) -> Result<Option<CodeownersEntry>> {
2121
// Trim the line and check for empty or comment lines
@@ -77,7 +77,7 @@ pub(crate) fn parse_line(
7777
}
7878

7979
/// Parse an owner string into an Owner struct
80-
fn parse_owner(owner_str: &str) -> Result<Owner> {
80+
pub(crate) fn parse_owner(owner_str: &str) -> Result<Owner> {
8181
let identifier = owner_str.to_string();
8282
let owner_type = if identifier.eq_ignore_ascii_case("NOOWNER") {
8383
OwnerType::Unowned

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub(crate) mod cli;
2-
pub(crate) mod core;
2+
pub mod core;
33
pub(crate) mod utils;

0 commit comments

Comments
 (0)