Skip to content

Commit

Permalink
benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-toth committed Dec 21, 2023
1 parent b5aa134 commit 6d8ad17
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 0 deletions.
72 changes: 72 additions & 0 deletions datafusion/expr/src/tree_node/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,75 @@ where
}
Ok(v)
}

#[cfg(test)]
mod test {
use crate::{and, lit, Expr};
use datafusion_common::tree_node::{Transformed, TreeNode, TreeNodeRecursion};
use std::time::Instant;

fn create_and_tree(level: u32) -> Expr {
if level == 0 {
lit(true)
} else {
and(create_and_tree(level - 1), create_and_tree(level - 1))
}
}

#[test]
fn transform_test() {
let now = Instant::now();
let mut and_tree = create_and_tree(25);
println!("create_and_tree: {}", now.elapsed().as_millis());

let now = Instant::now();
and_tree = and_tree
.transform_down_old(&mut |e| Ok(Transformed::No(e)))
.unwrap();
println!("and_tree.transform_down_old: {}", now.elapsed().as_millis());

let now = Instant::now();
let mut and_tree_clone = and_tree.clone();
println!("and_tree.clone: {}", now.elapsed().as_millis());

let now = Instant::now();
and_tree_clone
.transform_down(&mut |_e| Ok(TreeNodeRecursion::Continue))
.unwrap();
println!(
"and_tree_clone.transform_down: {}",
now.elapsed().as_millis()
);

println!("results: {}", and_tree == and_tree_clone);

let now = Instant::now();
and_tree = and_tree
.transform_down_old(&mut |e| match e {
Expr::Literal(_) => Ok(Transformed::Yes(lit(false))),
o => Ok(Transformed::No(o)),
})
.unwrap();
println!(
"and_tree.transform_down_old 2: {}",
now.elapsed().as_millis()
);

let now = Instant::now();
and_tree_clone
.transform_down(&mut |e| match e {
Expr::Literal(_) => {
*e = lit(false);
Ok(TreeNodeRecursion::Continue)
}
_ => Ok(TreeNodeRecursion::Continue),
})
.unwrap();
println!(
"and_tree_clone.transform_down 2: {}",
now.elapsed().as_millis()
);

println!("results: {}", and_tree == and_tree_clone);
}
}
72 changes: 72 additions & 0 deletions datafusion/expr/src/tree_node/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,75 @@ impl TreeNode for LogicalPlan {
Ok(tnr)
}
}

#[cfg(test)]
mod test {
use crate::{LogicalPlanBuilder, LogicalPlan};
use datafusion_common::tree_node::{Transformed, TreeNode, TreeNodeRecursion};
use std::time::Instant;

fn create_union_tree(level: u32) -> LogicalPlanBuilder {
if level == 0 {
LogicalPlanBuilder::empty(true)
} else {
create_union_tree(level - 1).union(create_union_tree(level - 1).build().unwrap()).unwrap()
}
}

#[test]
fn transform_test() {
let now = Instant::now();
let mut union_tree = create_union_tree(25).build().unwrap();
println!("create_union_tree: {}", now.elapsed().as_millis());

let now = Instant::now();
union_tree = union_tree
.transform_down_old(&mut |p| Ok(Transformed::No(p)))
.unwrap();
println!("union_tree.transform_down_old: {}", now.elapsed().as_millis());

let now = Instant::now();
let mut union_tree_clone = union_tree.clone();
println!("union_tree.clone: {}", now.elapsed().as_millis());

let now = Instant::now();
union_tree_clone
.transform_down(&mut |_p| Ok(TreeNodeRecursion::Continue))
.unwrap();
println!(
"union_tree_clone.transform_down: {}",
now.elapsed().as_millis()
);

println!("results: {}", union_tree == union_tree_clone);

let now = Instant::now();
union_tree = union_tree
.transform_down_old(&mut |p| match p {
LogicalPlan::EmptyRelation(_) => Ok(Transformed::Yes(LogicalPlanBuilder::empty(false).build().unwrap())),
o => Ok(Transformed::No(o)),
})
.unwrap();
println!(
"union_tree.transform_down_old 2: {}",
now.elapsed().as_millis()
);

let now = Instant::now();
union_tree_clone
.transform_down(&mut |p| match p {
LogicalPlan::EmptyRelation(_) => {
*p = LogicalPlanBuilder::empty(false).build().unwrap();
Ok(TreeNodeRecursion::Continue)
}
_ => Ok(TreeNodeRecursion::Continue),
})
.unwrap();
println!(
"union_tree_clone.transform_down 2: {}",
now.elapsed().as_millis()
);

println!("results: {}", union_tree == union_tree_clone);
}
}

0 comments on commit 6d8ad17

Please sign in to comment.