Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: introduce criterion (benchmark) #9

Merged
merged 5 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
522 changes: 522 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ resolver = "2"
members = [
"tellur_core", "editor",
]

[workspace.dependencies]
assert_matches = "1.5.0"
criterion = "0.5.1"
pretty_assertions = "1.4.1"
rstest = "0.24.0"
96 changes: 96 additions & 0 deletions flake.lock

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

38 changes: 38 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
description = "Development environment for tellur";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/release-24.11";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
};

outputs = { nixpkgs, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
in
{
devShells.default = pkgs.stdenv.mkDerivation {
name = "tellur-dev";
nativeBuildInputs = with pkgs; [
pkg-config
gnuplot
] ++ [
toolchain
];
buildInputs = with pkgs; [
openssl
libiconv
] ++ lib.optionals stdenvNoCC.isDarwin [
darwin.Security
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
];
};
}
);
}
11 changes: 9 additions & 2 deletions tellur_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ edition = "2021"

[dependencies]


[dev-dependencies]
pretty_assertions = "1.4.1"
rstest = "0.24.0"
assert_matches.workspace = true
criterion.workspace = true
pretty_assertions.workspace = true
rstest.workspace = true

[[bench]]
name = "benchmark"
harness = false
61 changes: 61 additions & 0 deletions tellur_core/benches/benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
mod or_with_andnot;
mod wrapped_not;

use criterion::{criterion_group, criterion_main};
use tellur_core::node::TellurNode;
use tellur_core::types::TellurTypedValueContainer;

use self::or_with_andnot::or_with_andnot_tree;
use self::wrapped_not::wrapped_not_tree;

fn plan_wrapped_not(c: &mut criterion::Criterion) {
c.bench_function("Planning Not-Wrapped Tree", |b| {
b.iter(|| {
let tree = wrapped_not_tree();
let _ = tree.planned();
})
});
}

fn run_wrapped_not(c: &mut criterion::Criterion) {
let planned = wrapped_not_tree().planned();
let vec = vec![TellurTypedValueContainer::new(
tellur_core::types::TellurTypedValue::Bool(true).into(),
)];
c.bench_function("Running Not-Wrapped Tree", |b| {
b.iter(|| {
let _ = planned.evaluate(vec.clone());
})
});
}

fn plan_or_with_andnot(c: &mut criterion::Criterion) {
c.bench_function("Planning Or-With-Andnot Tree", |b| {
b.iter(|| {
let tree = or_with_andnot_tree();
let _ = tree.planned();
})
});
}

fn run_or_with_andnot(c: &mut criterion::Criterion) {
let planned = or_with_andnot_tree().planned();
let vec = vec![
TellurTypedValueContainer::new(tellur_core::types::TellurTypedValue::Bool(true).into()),
TellurTypedValueContainer::new(tellur_core::types::TellurTypedValue::Bool(false).into()),
];
c.bench_function("Running Or-With-Andnot Tree", |b| {
b.iter(|| {
let _ = planned.evaluate(vec.clone());
})
});
}

criterion_group!(
benches,
plan_wrapped_not,
run_wrapped_not,
plan_or_with_andnot,
run_or_with_andnot
);
criterion_main!(benches);
92 changes: 92 additions & 0 deletions tellur_core/benches/or_with_andnot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
use std::collections::BTreeMap;

use tellur_core::node::TellurNode;
use tellur_core::tellur_std_node::logical::and::AndNode;
use tellur_core::tellur_std_node::logical::not::NotNode;
use tellur_core::tree::{NodeId, TellurNodeTree, TreeInput};
use tellur_core::types::{TellurRefType, TellurType};

pub fn or_with_andnot_tree() -> TellurNodeTree {
TellurNodeTree {
name: "or".to_string(),
parameters: BTreeMap::from([
(
"left".to_string(),
(TellurRefType::Immutable, TellurType::Bool),
),
(
"right".to_string(),
(TellurRefType::Immutable, TellurType::Bool),
),
]),
returns: BTreeMap::from([("result".to_string(), TellurType::Bool)]),
nodes: BTreeMap::from([
(
NodeId(0),
(
BTreeMap::from([(
"value".to_string(),
TreeInput::Parameter {
name: "left".to_string(),
},
)]),
Box::new(NotNode {}) as Box<dyn TellurNode>,
),
),
(
NodeId(1),
(
BTreeMap::from([(
"value".to_string(),
TreeInput::Parameter {
name: "right".to_string(),
},
)]),
Box::new(NotNode {}) as Box<dyn TellurNode>,
),
),
(
NodeId(2),
(
BTreeMap::from([
(
"left".to_string(),
TreeInput::NodeOutput {
id: NodeId(0),
output_name: "result".to_string(),
},
),
(
"right".to_string(),
TreeInput::NodeOutput {
id: NodeId(1),
output_name: "result".to_string(),
},
),
]),
Box::new(AndNode {}) as Box<dyn TellurNode>,
),
),
(
NodeId(3),
(
BTreeMap::from([(
"value".to_string(),
TreeInput::NodeOutput {
id: NodeId(2),
output_name: "result".to_string(),
},
)]),
Box::new(NotNode {}) as Box<dyn TellurNode>,
),
),
]),
outputs: BTreeMap::from([(
"result".to_string(),
TreeInput::NodeOutput {
id: NodeId(3),
output_name: "result".to_string(),
},
)]),
}
}
36 changes: 36 additions & 0 deletions tellur_core/benches/wrapped_not.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use std::collections::BTreeMap;

use tellur_core::node::TellurNode;
use tellur_core::tellur_std_node::logical::not::NotNode;
use tellur_core::tree::{NodeId, TellurNodeTree, TreeInput};
use tellur_core::types::{TellurRefType, TellurType};

pub fn wrapped_not_tree() -> TellurNodeTree {
TellurNodeTree {
name: "not_wrapped".to_string(),
parameters: BTreeMap::from([(
"value".to_string(),
(TellurRefType::Immutable, TellurType::Bool),
)]),
returns: BTreeMap::from([("result".to_string(), TellurType::Bool)]),
nodes: BTreeMap::from([(
NodeId(0),
(
BTreeMap::from([(
"value".to_string(),
TreeInput::Parameter {
name: "value".to_string(),
},
)]),
Box::new(NotNode {}) as Box<dyn TellurNode>,
),
)]),
outputs: BTreeMap::from([(
"result".to_string(),
TreeInput::NodeOutput {
id: NodeId(0),
output_name: "result".to_string(),
},
)]),
}
}
10 changes: 8 additions & 2 deletions tellur_core/src/composition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ pub enum ComponentId {
Output,
}

impl From<NodeId> for ComponentId {
fn from(id: NodeId) -> Self {
ComponentId::Node(id)
}
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Edge {
pub from: (ComponentId, String),
Expand All @@ -45,10 +51,10 @@ pub struct TellurComposition {
}

impl TellurComposition {
pub fn new(name: String) -> Self {
pub fn new(name: impl Into<String>) -> Self {
Self {
tree: TellurNodeTree {
name,
name: name.into(),
parameters: BTreeMap::new(),
returns: BTreeMap::new(),
nodes: BTreeMap::new(),
Expand Down
Loading