tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 9TOML 3CSS 1345 Definiciones

Fix yoga benchmark feature flag (#471)

* Fix yoga benchmark feature flag:

Feature flag was renamed in Cargo.toml but not in the code, causing it to
have no effect

* Add slotmap dependency for yoga benchmarks

129e31a56830b0de926042d913c1310ac3df4771 · por Nico Burns · (hace 3 años) · padre 18b6cf400 · ver el árbol en este commit

Delta semántico · 2

benches/benches/flexbox.rs

benches/benches/tree_creation.rs

4 archivos · +20 −19

diff --git a/benches/Cargo.toml b/benches/Cargo.toml
index bf856a69e..93291ca53 100644
--- a/benches/Cargo.toml
+++ b/benches/Cargo.toml
@@ -19,9 +19,10 @@ rand = { version = "0.8.5" }
 rand_chacha = "0.3.1"
 yoga = { version = "0.4.0", optional = true }
 ordered-float = { version = "3.4.0", optional = true }
+slotmap = { version = "1.0.6", optional = true }
 
 [features]
-yoga = ["dep:yoga", "dep:ordered-float"]
+yoga = ["dep:yoga", "dep:slotmap", "dep:ordered-float"]
 
 [[bench]]
 name = "tree_creation"
diff --git a/benches/benches/flexbox.rs b/benches/benches/flexbox.rs
index dcd311660..393bb996e 100644
--- a/benches/benches/flexbox.rs
+++ b/benches/benches/flexbox.rs
@@ -6,11 +6,11 @@ use taffy::prelude::*;
 use taffy::style::Style;
 use taffy_benchmarks::{build_deep_tree, Randomizeable};
 
-#[cfg(feature = "yoga_benchmark")]
+#[cfg(feature = "yoga")]
 use slotmap::SlotMap;
-#[cfg(feature = "yoga_benchmark")]
+#[cfg(feature = "yoga")]
 use taffy_benchmarks::yoga_helpers;
-#[cfg(feature = "yoga_benchmark")]
+#[cfg(feature = "yoga")]
 use yoga_helpers::yg;
 
 /// Build a random leaf node
@@ -39,7 +39,7 @@ fn build_taffy_flat_hierarchy(total_node_count: u32) -> (Taffy, NodeId) {
     (taffy, root)
 }
 
-#[cfg(feature = "yoga_benchmark")]
+#[cfg(feature = "yoga")]
 /// A tree with many children that have shallow depth
 fn build_yoga_flat_hierarchy(total_node_count: u32) -> (yg::YogaTree, yg::NodeId) {
     let mut tree = SlotMap::new();
@@ -76,7 +76,7 @@ fn build_taffy_deep_hierarchy(node_count: u32, branching_factor: u32) -> (Taffy,
     (taffy, root)
 }
 
-#[cfg(feature = "yoga_benchmark")]
+#[cfg(feature = "yoga")]
 /// A tree with a higher depth for a more realistic scenario
 fn build_yoga_deep_hierarchy(node_count: u32, branching_factor: u32) -> (yg::YogaTree, yg::NodeId) {
     let mut rng = ChaCha8Rng::seed_from_u64(12345);
@@ -111,7 +111,7 @@ fn build_taffy_huge_nested_hierarchy(node_count: u32, branching_factor: u32) ->
     (taffy, root)
 }
 
-#[cfg(feature = "yoga_benchmark")]
+#[cfg(feature = "yoga")]
 /// A deep tree that matches the shape and styling that yoga use on their benchmarks
 fn build_yoga_huge_nested_hierarchy(node_count: u32, branching_factor: u32) -> (yg::YogaTree, yg::NodeId) {
     let style = Style {
@@ -146,7 +146,7 @@ fn build_yoga_huge_nested_hierarchy(node_count: u32, branching_factor: u32) -> (
 fn taffy_benchmarks(c: &mut Criterion) {
     let mut group = c.benchmark_group("yoga 'huge nested'");
     for node_count in [1_000u32, 10_000, 100_000].iter() {
-        #[cfg(feature = "yoga_benchmark")]
+        #[cfg(feature = "yoga")]
         group.bench_with_input(BenchmarkId::new("Yoga", node_count), node_count, |b, &node_count| {
             b.iter_batched(
                 || build_yoga_huge_nested_hierarchy(node_count, 10),
@@ -170,9 +170,9 @@ fn taffy_benchmarks(c: &mut Criterion) {
     let mut group = c.benchmark_group("big trees (wide)");
     group.sample_size(10);
     for node_count in [1_000u32, 10_000, 100_000].iter() {
-        #[cfg(feature = "yoga_benchmark")]
+        #[cfg(feature = "yoga")]
         let benchmark_id = BenchmarkId::new(format!("Yoga (2-level hierarchy)"), node_count);
-        #[cfg(feature = "yoga_benchmark")]
+        #[cfg(feature = "yoga")]
         group.bench_with_input(benchmark_id, node_count, |b, &node_count| {
             b.iter_batched(
                 || build_yoga_flat_hierarchy(node_count),
@@ -198,7 +198,7 @@ fn taffy_benchmarks(c: &mut Criterion) {
     group.sample_size(10);
     let benches = [(4000, "(12-level hierarchy)"), (10_000, "(14-level hierarchy)"), (100_000, "(17-level hierarchy)")];
     for (node_count, label) in benches.iter() {
-        #[cfg(feature = "yoga_benchmark")]
+        #[cfg(feature = "yoga")]
         group.bench_with_input(BenchmarkId::new(format!("Yoga {label}"), node_count), node_count, |b, &node_count| {
             b.iter_batched(
                 || build_yoga_deep_hierarchy(node_count, 2),
@@ -221,7 +221,7 @@ fn taffy_benchmarks(c: &mut Criterion) {
     let mut group = c.benchmark_group("super deep (1000-level hierarchy)");
     group.sample_size(10);
     for node_count in [1000u32].iter() {
-        #[cfg(feature = "yoga_benchmark")]
+        #[cfg(feature = "yoga")]
         group.bench_with_input(BenchmarkId::new("Yoga", node_count), node_count, |b, &node_count| {
             b.iter_batched(
                 || build_yoga_deep_hierarchy(node_count, 2),
diff --git a/benches/benches/tree_creation.rs b/benches/benches/tree_creation.rs
index ff316555c..0c2178d50 100644
--- a/benches/benches/tree_creation.rs
+++ b/benches/benches/tree_creation.rs
@@ -5,11 +5,11 @@ use rand_chacha::ChaCha8Rng;
 use taffy::prelude::*;
 use taffy::style::Style;
 
-#[cfg(feature = "yoga_benchmark")]
+#[cfg(feature = "yoga")]
 use slotmap::SlotMap;
-#[cfg(feature = "yoga_benchmark")]
+#[cfg(feature = "yoga")]
 use taffy_benchmarks::yoga_helpers;
-#[cfg(feature = "yoga_benchmark")]
+#[cfg(feature = "yoga")]
 use yoga_helpers::yg;
 
 /// Build a random leaf node
@@ -37,7 +37,7 @@ fn build_taffy_flat_hierarchy(total_node_count: u32, use_with_capacity: bool) ->
     (taffy, root)
 }
 
-#[cfg(feature = "yoga_benchmark")]
+#[cfg(feature = "yoga")]
 /// A tree with many children that have shallow depth
 fn build_yoga_flat_hierarchy(total_node_count: u32) -> (yg::YogaTree, yg::NodeId) {
     let mut tree = SlotMap::new();
@@ -62,9 +62,9 @@ fn build_yoga_flat_hierarchy(total_node_count: u32) -> (yg::YogaTree, yg::NodeId
 fn taffy_benchmarks(c: &mut Criterion) {
     let mut group = c.benchmark_group("Tree creation");
     for node_count in [1_000u32, 10_000, 100_000].iter() {
-        #[cfg(feature = "yoga_benchmark")]
+        #[cfg(feature = "yoga")]
         let benchmark_id = BenchmarkId::new(format!("Yoga"), node_count);
-        #[cfg(feature = "yoga_benchmark")]
+        #[cfg(feature = "yoga")]
         group.bench_with_input(benchmark_id, node_count, |b, &node_count| {
             b.iter(|| {
                 let (taffy, root) = build_yoga_flat_hierarchy(node_count);
diff --git a/benches/src/lib.rs b/benches/src/lib.rs
index 73d047cc0..42c5a4662 100644
--- a/benches/src/lib.rs
+++ b/benches/src/lib.rs
@@ -1,4 +1,4 @@
-#[cfg(feature = "yoga_benchmark")]
+#[cfg(feature = "yoga")]
 pub mod yoga_helpers;
 
 mod random_style;