This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git


The following commit(s) were added to refs/heads/main by this push:
     new 9cc563095 feat(rust): support profile all data types in rust benchmark 
(#2801)
9cc563095 is described below

commit 9cc563095fee3ff491818d700b6d019b34dfe24c
Author: Shawn Yang <[email protected]>
AuthorDate: Wed Oct 22 14:51:25 2025 +0800

    feat(rust): support profile all data types in rust benchmark (#2801)
    
    <!--
    **Thanks for contributing to Apache Fory™.**
    
    **If this is your first time opening a PR on fory, you can refer to
    
[CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).**
    
    Contribution Checklist
    
    - The **Apache Fory™** community has requirements on the naming of pr
    titles. You can also find instructions in
    [CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).
    
    - Apache Fory™ has a strong focus on performance. If the PR you submit
    will have an impact on performance, please benchmark it first and
    provide the benchmark result here.
    -->
    
    ## Why?
    
    <!-- Describe the purpose of this PR. -->
    
    ## What does this PR do?
    
    support profile all data types in rust benchmark
    
    ## Related issues
    
    <!--
    Is there any related issue? If this PR closes them you say say
    fix/closes:
    
    - #xxxx0
    - #xxxx1
    - Fixes #xxxx2
    -->
    
    ## Does this PR introduce any user-facing change?
    
    <!--
    If any user-facing interface changes, please [open an
    issue](https://github.com/apache/fory/issues/new/choose) describing the
    need to do so and update the document if necessary.
    
    Delete section if not applicable.
    -->
    
    - [ ] Does this PR introduce any public API change?
    - [ ] Does this PR introduce any binary protocol compatibility change?
    
    ## Benchmark
    
    <!--
    When the PR has an impact on performance (if you don't know whether the
    PR will have an impact on performance, you can submit the PR first, and
    if it will have impact on performance, the code reviewer will explain
    it), be sure to attach a benchmark data here.
    
    Delete section if not applicable.
    -->
---
 rust/benches/README.md   |   2 +-
 rust/benches/src/main.rs | 101 +++++++++++++++++++++++++++++++++++++----------
 2 files changed, 81 insertions(+), 22 deletions(-)

diff --git a/rust/benches/README.md b/rust/benches/README.md
index 9db37f871..0fd64f542 100644
--- a/rust/benches/README.md
+++ b/rust/benches/README.md
@@ -1,7 +1,7 @@
 ## How to generate flamegraph
 
 ```bash
-cargo flamegraph --bin fory_profiler -- --operation deserialize --serializer 
fory
+cargo flamegraph --bin fory_profiler -- --operation deserialize --serializer 
fory -t e-commerce-data
 ```
 
 detailed command:
diff --git a/rust/benches/src/main.rs b/rust/benches/src/main.rs
index 2d740088a..786fd71d1 100644
--- a/rust/benches/src/main.rs
+++ b/rust/benches/src/main.rs
@@ -17,6 +17,9 @@
 
 use clap::{Parser, ValueEnum};
 use fory_benchmarks::models::complex::ECommerceData;
+use fory_benchmarks::models::medium::{Company, Person};
+use fory_benchmarks::models::realworld::SystemData;
+use fory_benchmarks::models::simple::{SimpleList, SimpleMap, SimpleStruct};
 use fory_benchmarks::models::TestDataGenerator;
 use fory_benchmarks::serializers::fory::ForySerializer;
 use fory_benchmarks::serializers::protobuf::ProtobufSerializer;
@@ -35,6 +38,17 @@ pub enum SerializerType {
     Fory,
 }
 
+#[derive(Debug, Clone, Copy, ValueEnum)]
+pub enum DataType {
+    SimpleStruct,
+    SimpleList,
+    SimpleMap,
+    Person,
+    Company,
+    ECommerceData,
+    SystemData,
+}
+
 #[derive(Parser)]
 #[command(name = "fory_profiler")]
 #[command(about = "A profiler for Fory and Protobuf serialization 
performance")]
@@ -54,6 +68,10 @@ struct Cli {
     /// Data size to use (small, medium, large)
     #[arg(short, long, default_value = "large")]
     data_size: String,
+
+    /// Data type to profile
+    #[arg(short = 't', long, value_enum, default_value = "e-commerce-data")]
+    data_type: DataType,
 }
 
 fn profile<T, S>(num_iterations: usize, data: &T, serializer: &S, operation: 
Operation)
@@ -117,38 +135,79 @@ where
     println!("Profiling complete! Ran {} iterations", num_iterations);
 }
 
+fn profile_with_serializer<T>(
+    num_iterations: usize,
+    data: &T,
+    serializer_type: SerializerType,
+    operation: Operation,
+) where
+    T: Clone,
+    ProtobufSerializer: Serializer<T>,
+    ForySerializer: Serializer<T>,
+{
+    match serializer_type {
+        SerializerType::Protobuf => {
+            let serializer = ProtobufSerializer::new();
+            profile(num_iterations, data, &serializer, operation);
+        }
+        SerializerType::Fory => {
+            let serializer = ForySerializer::new();
+            profile(num_iterations, data, &serializer, operation);
+        }
+    }
+}
+
+fn generate_data<T: TestDataGenerator>(data_size: &str) -> T::Data {
+    match data_size {
+        "small" => T::generate_small(),
+        "medium" => T::generate_medium(),
+        "large" => T::generate_large(),
+        _ => {
+            eprintln!("Invalid data size: {}. Using 'large' instead.", 
data_size);
+            T::generate_large()
+        }
+    }
+}
+
 fn main() {
     let cli = Cli::parse();
 
     println!("Starting profiling...");
     println!("Operation: {:?}", cli.operation);
     println!("Serializer: {:?}", cli.serializer);
+    println!("Data type: {:?}", cli.data_type);
     println!("Iterations: {}", cli.iterations);
     println!("Data size: {}", cli.data_size);
 
-    // Generate data based on size parameter
-    let data = match cli.data_size.as_str() {
-        "small" => ECommerceData::generate_small(),
-        "medium" => ECommerceData::generate_medium(),
-        "large" => ECommerceData::generate_large(),
-        _ => {
-            eprintln!(
-                "Invalid data size: {}. Using 'large' instead.",
-                cli.data_size
-            );
-            ECommerceData::generate_large()
+    // Generate data and profile based on data type
+    match cli.data_type {
+        DataType::SimpleStruct => {
+            let data = generate_data::<SimpleStruct>(&cli.data_size);
+            profile_with_serializer(cli.iterations, &data, cli.serializer, 
cli.operation);
         }
-    };
-
-    // Create serializer based on type
-    match cli.serializer {
-        SerializerType::Protobuf => {
-            let serializer = ProtobufSerializer::new();
-            profile(cli.iterations, &data, &serializer, cli.operation);
+        DataType::SimpleList => {
+            let data = generate_data::<SimpleList>(&cli.data_size);
+            profile_with_serializer(cli.iterations, &data, cli.serializer, 
cli.operation);
         }
-        SerializerType::Fory => {
-            let serializer = ForySerializer::new();
-            profile(cli.iterations, &data, &serializer, cli.operation);
+        DataType::SimpleMap => {
+            let data = generate_data::<SimpleMap>(&cli.data_size);
+            profile_with_serializer(cli.iterations, &data, cli.serializer, 
cli.operation);
+        }
+        DataType::Person => {
+            let data = generate_data::<Person>(&cli.data_size);
+            profile_with_serializer(cli.iterations, &data, cli.serializer, 
cli.operation);
+        }
+        DataType::Company => {
+            let data = generate_data::<Company>(&cli.data_size);
+            profile_with_serializer(cli.iterations, &data, cli.serializer, 
cli.operation);
+        }
+        DataType::ECommerceData => {
+            let data = generate_data::<ECommerceData>(&cli.data_size);
+            profile_with_serializer(cli.iterations, &data, cli.serializer, 
cli.operation);
+        }
+        DataType::SystemData => {
+            let data = generate_data::<SystemData>(&cli.data_size);
+            profile_with_serializer(cli.iterations, &data, cli.serializer, 
cli.operation);
         }
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to