Skip to content

Commit

Permalink
Change: nasl-syntax: benchmark tests iterate (#1534)
Browse files Browse the repository at this point in the history
Changes that the bench tests within nasl-syntax do indeed test all
Statements instead of just the first.

Additionally it tests smb_nt.inc as it is one of the largest nasl files
within the community feed.
  • Loading branch information
nichtsfrei authored Dec 11, 2023
1 parent a40b616 commit f70fd53
Show file tree
Hide file tree
Showing 2 changed files with 9,552 additions and 20 deletions.
31 changes: 11 additions & 20 deletions rust/nasl-syntax/benches/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,22 @@
//
// SPDX-License-Identifier: GPL-2.0-or-later

use std::{env, fs, path::PathBuf};

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use nasl_syntax::parse;

fn loadfile(filename: &str) -> PathBuf {
let mut current = env::current_dir().unwrap();
let reset = current.clone();
// move to nasl-syntax
current.push("nasl-syntax");
if !current.is_dir() {
// we were already in nasl-syntax and have to reset
current = reset;
}
current.push("benches");
current.push(filename);
current
pub fn simple_parse_benchmark(c: &mut Criterion) {
let code = include_str!("simple_parse.nasl");
c.bench_function("simple_parse", |b| {
b.iter(|| parse(black_box(&code)).map(|x| x.unwrap()).count())
});
}

pub fn simple_parse_benchmark(c: &mut Criterion) {
let code: String = fs::read(loadfile("simple_parse.nasl"))
.map(|bs| bs.iter().map(|&b| b as char).collect())
.unwrap();
c.bench_function("simple_parse", |b| b.iter(|| parse(black_box(&code))));
pub fn parse_large_benchmark(c: &mut Criterion) {
let code = include_str!("smb_nt.inc");
c.bench_function(&format!("smb_nt.inc {}", code.len()), |b| {
b.iter(|| parse(black_box(&code)).map(|x| x.unwrap()).count())
});
}

criterion_group!(benches, simple_parse_benchmark);
criterion_group!(benches, simple_parse_benchmark, parse_large_benchmark);
criterion_main!(benches);
Loading

0 comments on commit f70fd53

Please sign in to comment.