10

Github Add a benchmark for the compare function · Issue #390 · dotenv-linter/dot...

 3 years ago
source link: https://github.com/dotenv-linter/dotenv-linter/issues/390
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Description

To do refactoring we need to have benchmarks. We already have a benchmark for the check function:

// benches/check.rs
pub fn check_benchmark(c: &mut Criterion) {
    let temp = tempdir().expect("create tempdir");
    let path = temp.into_path();

    let current_dir = env::current_dir().expect("get current dir");
    let app = dotenv_linter::cli::new(current_dir.as_os_str());
    let matches = app.get_matches_from(vec!["dotenv-linter", path.to_str().expect("path to str")]);

    fs::copy("benches/fixtures/simple.env", path.join(".env")).expect("copy .env file");

    c.bench_function("dotenv_linter check", |b| {
        // Disable output to STDOUT
        #[cfg(not(windows))]
        let _print_gag = Gag::stdout().expect("disable stdout");

        b.iter(|| dotenv_linter::check(black_box(&matches), black_box(&current_dir)))
    });
}

It needs to write the benchmark for the compare function.

Implementation

You can take the benchmark for the check function as an example.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK