Skip to content

Commit

Permalink
Add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
kraigher committed Nov 22, 2023
1 parent 33f6388 commit e51d9e7
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions vhdl_lang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ itertools = "0"
tempfile = "3"
pretty_assertions = "1"
assert_matches = "1"
brunch = "0"

[[bench]]
name = "benchmark"
harness = false

[features]
default = []
71 changes: 71 additions & 0 deletions vhdl_lang/benches/benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2023, Olof Kraigher [email protected]

use brunch::{Bench, Benches};
use std::path::Path;
use vhdl_lang::{Config, MessagePrinter, NullMessages, Project};

fn load_config(include_example_project: bool) -> Config {
let repo_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("..");

let mut config = Config::default();
config.append(
&Config::read_file_path(&repo_root.join("vhdl_libraries").join("vhdl_ls.toml"))
.expect("Failed to read installed config file"),
&mut MessagePrinter::default(),
);

if include_example_project {
config.append(
&Config::read_file_path(&repo_root.join("example_project").join("vhdl_ls.toml"))
.expect("Failed to read project config file"),
&mut MessagePrinter::default(),
);
}

config
}

fn main() {
let mut benches = Benches::default();

{
// Only use standard libraries to benchmark parse and analyze as the time taken to get 100 samples
// is very big with the example project
let config = load_config(false);
benches.push(Bench::new("parse and analyze").with_samples(10).run(|| {
let mut project = Project::from_config(config.clone(), &mut NullMessages);
project.analyse();
}));
}

{
let mut project = Project::from_config(load_config(true), &mut NullMessages);
project.analyse();

let integer = project
.public_symbols()
.find(|ent| matches!(ent.designator().as_identifier(), Some(sym) if sym.name_utf8() == "INTEGER"))
.unwrap();

benches.push(Bench::new("find all references").run(|| {
assert!(!project.find_all_references(integer).is_empty());
}));

let integer_pos = integer.decl_pos().unwrap();
benches.push(Bench::new("item at cursor").run(|| {
assert_eq!(
project
.item_at_cursor(&integer_pos.source, integer_pos.start())
.unwrap()
.1,
integer
);
}));
}

benches.finish();
}

0 comments on commit e51d9e7

Please sign in to comment.