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 4beaa2a1f feat(rust): add rust benchmark report script and result 
(#2835)
4beaa2a1f is described below

commit 4beaa2a1f17cee50b4a3102d4b247a2b45286bf3
Author: Shawn Yang <[email protected]>
AuthorDate: Sun Oct 26 18:56:47 2025 +0800

    feat(rust): add rust benchmark report script and result (#2835)
    
    ## Why?
    
    <!-- Describe the purpose of this PR. -->
    
    ## What does this PR do?
    
    Add:
    
    
    ### Serialize Results (sorted by fastest TPS)
    
    | Datatype | Size | Operation | Fory TPS | JSON TPS | Protobuf TPS |
    Fastest |
    | -------------- | ------ | --------- | ---------- | ---------- |
    ------------ | ------- |
    | simple_struct | small | serialize | 35,729,598 | 10,167,045 |
    8,633,342 | fory |
    | simple_struct | medium | serialize | 34,988,279 | 9,737,098 |
    6,433,350 | fory |
    | simple_struct | large | serialize | 31,801,558 | 4,545,041 | 7,420,049
    | fory |
    | simple_list | small | serialize | 27,726,945 | 4,874,957 | 4,643,172 |
    fory |
    | simple_map | small | serialize | 22,862,369 | 3,888,025 | 2,695,999 |
    fory |
    | person | small | serialize | 13,632,522 | 1,345,189 | 1,475,035 | fory
    |
    | company | small | serialize | 10,063,906 | 761,673 | 896,620 | fory |
    | system_data | small | serialize | 5,382,131 | 468,033 | 569,930 | fory
    |
    | simple_list | medium | serialize | 4,770,765 | 401,558 | 397,551 |
    fory |
    | person | medium | serialize | 3,839,656 | 337,610 | 369,031 | fory |
    | ecommerce_data | small | serialize | 2,350,729 | 206,262 | 256,970 |
    fory |
    | simple_map | medium | serialize | 2,128,973 | 204,319 | 193,132 | fory
    |
    | person | large | serialize | 907,853 | 79,631 | 91,408 | fory |
    | simple_list | large | serialize | 606,061 | 41,061 | 44,565 | fory |
    | company | medium | serialize | 412,507 | 33,835 | 37,590 | fory |
    | simple_map | large | serialize | 177,847 | 18,419 | 18,668 | fory |
    | system_data | medium | serialize | 174,240 | 11,896 | 14,753 | fory |
    | ecommerce_data | medium | serialize | 59,977 | 4,699 | 5,242 | fory |
    | system_data | large | serialize | 10,671 | 876 | 1,040 | fory |
    | company | large | serialize | 9,183 | 793 | 880 | fory |
    | ecommerce_data | large | serialize | 3,727 | 266 | 295 | fory |
    
    ### Deserialize Results (sorted by fastest TPS)
    
    | Datatype | Size | Operation | Fory TPS | JSON TPS | Protobuf TPS |
    Fastest |
    | -------------- | ------ | ----------- | ---------- | ---------- |
    ------------ | ------- |
    | simple_struct | small | deserialize | 31,476,235 | 12,948,168 |
    28,280,543 | fory |
    | simple_struct | medium | deserialize | 30,077,902 | 10,431,118 |
    23,012,841 | fory |
    | simple_struct | large | deserialize | 28,201,585 | 8,955,759 |
    23,528,858 | fory |
    | simple_list | small | deserialize | 6,129,329 | 3,599,582 | 4,429,286
    | fory |
    | simple_map | small | deserialize | 3,686,364 | 3,090,426 | 3,477,051 |
    fory |
    | person | small | deserialize | 1,924,372 | 1,214,388 | 1,675,631 |
    fory |
    | company | small | deserialize | 1,145,593 | 718,597 | 917,431 | fory |
    | system_data | small | deserialize | 644,870 | 421,106 | 549,209 | fory
    |
    | simple_list | medium | deserialize | 460,745 | 305,409 | 337,336 |
    fory |
    | person | medium | deserialize | 371,016 | 265,280 | 266,333 | fory |
    | ecommerce_data | small | deserialize | 278,427 | 183,237 | 241,109 |
    fory |
    | simple_map | medium | deserialize | 171,774 | 126,638 | 119,323 | fory
    |
    | person | large | deserialize | 84,839 | 63,975 | 61,820 | fory |
    | simple_list | large | deserialize | 54,348 | 33,962 | 38,776 | fory |
    | company | medium | deserialize | 35,195 | 24,474 | 25,057 | fory |
    | simple_map | large | deserialize | 16,501 | 10,920 | 10,853 | fory |
    | system_data | medium | deserialize | 14,322 | 9,205 | 10,565 | fory |
    | ecommerce_data | medium | deserialize | 5,622 | 3,820 | 4,249 | fory |
    | system_data | large | deserialize | 961 | 634 | 706 | fory |
    | company | large | deserialize | 836 | 623 | 623 | fory |
    | ecommerce_data | large | deserialize | 298 | 204 | 217 | fory |
    
    <img width="1800" height="500" alt="person"
    
src="https://github.com/user-attachments/assets/b092b7ba-476b-4a4b-83bc-5f5220aefda3";
    />
    <img width="1800" height="500" alt="system_data"
    
src="https://github.com/user-attachments/assets/c0a048ed-5265-40ef-a918-ebb012f78edd";
    />
    <img width="1800" height="500" alt="ecommerce_data"
    
src="https://github.com/user-attachments/assets/caebddec-11e5-4201-b9a8-73d77a2f8c14";
    />
    
    ## 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.
    -->
---
 README.md                               |  16 +++
 docs/benchmarks/rust/README.md          | 118 +++++++++++++++++
 docs/benchmarks/rust/company.png        | Bin 0 -> 44643 bytes
 docs/benchmarks/rust/ecommerce_data.png | Bin 0 -> 44956 bytes
 docs/benchmarks/rust/person.png         | Bin 0 -> 40224 bytes
 docs/benchmarks/rust/simple_list.png    | Bin 0 -> 39423 bytes
 docs/benchmarks/rust/simple_map.png     | Bin 0 -> 45555 bytes
 docs/benchmarks/rust/simple_struct.png  | Bin 0 -> 43007 bytes
 docs/benchmarks/rust/system_data.png    | Bin 0 -> 41417 bytes
 rust/benches/README.md                  | 119 +++++++++++++++++
 rust/benches/benchmark_report.py        | 226 ++++++++++++++++++++++++++++++++
 11 files changed, 479 insertions(+)

diff --git a/README.md b/README.md
index 7445de3c8..0ce0d43c9 100644
--- a/README.md
+++ b/README.md
@@ -84,6 +84,22 @@ Where `Struct` is a class with [100 primitive 
fields](https://github.com/apache/
 
 See [benchmarks](https://github.com/apache/fory/tree/main/docs/benchmarks) for 
more benchmarks about type forward/backward compatibility, off-heap support, 
zero-copy serialization.
 
+### Rust Serialization
+
+**ecommerce_data**
+
+<p align="center">
+<img src="docs/benchmarks/rust/ecommerce_data.png" width="90%">
+</p>
+
+**system_data**
+
+<p align="center">
+<img src="docs/benchmarks/rust/system_data.png" width="90%">
+</p>
+
+See [Rust Benchmarks](https://github.com/apache/fory/tree/main/rust/benches) 
for more benchmarks about Apache Fory Rust Serialization.
+
 ## Installation
 
 ### Java
diff --git a/docs/benchmarks/rust/README.md b/docs/benchmarks/rust/README.md
new file mode 100644
index 000000000..22be785b2
--- /dev/null
+++ b/docs/benchmarks/rust/README.md
@@ -0,0 +1,118 @@
+## Performance Comparison Report
+
+_Generated on 2025-10-26 18:36:41_
+
+How to generate performance report:
+
+```bash
+cd rust/benches
+cargo bench 2>&1 | tee cargo_bench.log
+python benchmark_report.py --log-file cargo_bench.log 
--output-dir=report_output
+```
+
+### Hardware & OS Info
+
+| Key                  | Value         |
+| -------------------- | ------------- |
+| OS                   | Darwin 24.5.0 |
+| Machine              | arm64         |
+| Processor            | arm           |
+| CPU Cores (Physical) | 12            |
+| CPU Cores (Logical)  | 12            |
+| Total RAM (GB)       | 48.0          |
+
+### Benchmark Plots
+
+**company**
+
+<p align="center">
+<img src="company.png" width="90%">
+</p>
+
+**ecommerce_data**
+
+<p align="center">
+<img src="ecommerce_data.png" width="90%">
+</p>
+
+**person**
+
+<p align="center">
+<img src="person.png" width="90%">
+</p>
+
+**simple_list**
+
+<p align="center">
+<img src="simple_list.png" width="90%">
+</p>
+
+**simple_map**
+
+<p align="center">
+<img src="simple_map.png" width="90%">
+</p>
+
+**simple_struct**
+
+<p align="center">
+<img src="simple_struct.png" width="90%">
+</p>
+
+**system_data**
+
+<p align="center">
+<img src="system_data.png" width="90%">
+</p>
+
+### Serialize Results (sorted by fastest TPS)
+
+| Datatype       | Size   | Operation | Fory TPS   | JSON TPS   | Protobuf TPS 
| Fastest |
+| -------------- | ------ | --------- | ---------- | ---------- | ------------ 
| ------- |
+| simple_struct  | small  | serialize | 35,729,598 | 10,167,045 | 8,633,342    
| fory    |
+| simple_struct  | medium | serialize | 34,988,279 | 9,737,098  | 6,433,350    
| fory    |
+| simple_struct  | large  | serialize | 31,801,558 | 4,545,041  | 7,420,049    
| fory    |
+| simple_list    | small  | serialize | 27,726,945 | 4,874,957  | 4,643,172    
| fory    |
+| simple_map     | small  | serialize | 22,862,369 | 3,888,025  | 2,695,999    
| fory    |
+| person         | small  | serialize | 13,632,522 | 1,345,189  | 1,475,035    
| fory    |
+| company        | small  | serialize | 10,063,906 | 761,673    | 896,620      
| fory    |
+| system_data    | small  | serialize | 5,382,131  | 468,033    | 569,930      
| fory    |
+| simple_list    | medium | serialize | 4,770,765  | 401,558    | 397,551      
| fory    |
+| person         | medium | serialize | 3,839,656  | 337,610    | 369,031      
| fory    |
+| ecommerce_data | small  | serialize | 2,350,729  | 206,262    | 256,970      
| fory    |
+| simple_map     | medium | serialize | 2,128,973  | 204,319    | 193,132      
| fory    |
+| person         | large  | serialize | 907,853    | 79,631     | 91,408       
| fory    |
+| simple_list    | large  | serialize | 606,061    | 41,061     | 44,565       
| fory    |
+| company        | medium | serialize | 412,507    | 33,835     | 37,590       
| fory    |
+| simple_map     | large  | serialize | 177,847    | 18,419     | 18,668       
| fory    |
+| system_data    | medium | serialize | 174,240    | 11,896     | 14,753       
| fory    |
+| ecommerce_data | medium | serialize | 59,977     | 4,699      | 5,242        
| fory    |
+| system_data    | large  | serialize | 10,671     | 876        | 1,040        
| fory    |
+| company        | large  | serialize | 9,183      | 793        | 880          
| fory    |
+| ecommerce_data | large  | serialize | 3,727      | 266        | 295          
| fory    |
+
+### Deserialize Results (sorted by fastest TPS)
+
+| Datatype       | Size   | Operation   | Fory TPS   | JSON TPS   | Protobuf 
TPS | Fastest |
+| -------------- | ------ | ----------- | ---------- | ---------- | 
------------ | ------- |
+| simple_struct  | small  | deserialize | 31,476,235 | 12,948,168 | 28,280,543 
  | fory    |
+| simple_struct  | medium | deserialize | 30,077,902 | 10,431,118 | 23,012,841 
  | fory    |
+| simple_struct  | large  | deserialize | 28,201,585 | 8,955,759  | 23,528,858 
  | fory    |
+| simple_list    | small  | deserialize | 6,129,329  | 3,599,582  | 4,429,286  
  | fory    |
+| simple_map     | small  | deserialize | 3,686,364  | 3,090,426  | 3,477,051  
  | fory    |
+| person         | small  | deserialize | 1,924,372  | 1,214,388  | 1,675,631  
  | fory    |
+| company        | small  | deserialize | 1,145,593  | 718,597    | 917,431    
  | fory    |
+| system_data    | small  | deserialize | 644,870    | 421,106    | 549,209    
  | fory    |
+| simple_list    | medium | deserialize | 460,745    | 305,409    | 337,336    
  | fory    |
+| person         | medium | deserialize | 371,016    | 265,280    | 266,333    
  | fory    |
+| ecommerce_data | small  | deserialize | 278,427    | 183,237    | 241,109    
  | fory    |
+| simple_map     | medium | deserialize | 171,774    | 126,638    | 119,323    
  | fory    |
+| person         | large  | deserialize | 84,839     | 63,975     | 61,820     
  | fory    |
+| simple_list    | large  | deserialize | 54,348     | 33,962     | 38,776     
  | fory    |
+| company        | medium | deserialize | 35,195     | 24,474     | 25,057     
  | fory    |
+| simple_map     | large  | deserialize | 16,501     | 10,920     | 10,853     
  | fory    |
+| system_data    | medium | deserialize | 14,322     | 9,205      | 10,565     
  | fory    |
+| ecommerce_data | medium | deserialize | 5,622      | 3,820      | 4,249      
  | fory    |
+| system_data    | large  | deserialize | 961        | 634        | 706        
  | fory    |
+| company        | large  | deserialize | 836        | 623        | 623        
  | fory    |
+| ecommerce_data | large  | deserialize | 298        | 204        | 217        
  | fory    |
diff --git a/docs/benchmarks/rust/company.png b/docs/benchmarks/rust/company.png
new file mode 100644
index 000000000..eee9de23f
Binary files /dev/null and b/docs/benchmarks/rust/company.png differ
diff --git a/docs/benchmarks/rust/ecommerce_data.png 
b/docs/benchmarks/rust/ecommerce_data.png
new file mode 100644
index 000000000..11a507329
Binary files /dev/null and b/docs/benchmarks/rust/ecommerce_data.png differ
diff --git a/docs/benchmarks/rust/person.png b/docs/benchmarks/rust/person.png
new file mode 100644
index 000000000..d31e0d030
Binary files /dev/null and b/docs/benchmarks/rust/person.png differ
diff --git a/docs/benchmarks/rust/simple_list.png 
b/docs/benchmarks/rust/simple_list.png
new file mode 100644
index 000000000..00c5b7d4e
Binary files /dev/null and b/docs/benchmarks/rust/simple_list.png differ
diff --git a/docs/benchmarks/rust/simple_map.png 
b/docs/benchmarks/rust/simple_map.png
new file mode 100644
index 000000000..1142bb3fb
Binary files /dev/null and b/docs/benchmarks/rust/simple_map.png differ
diff --git a/docs/benchmarks/rust/simple_struct.png 
b/docs/benchmarks/rust/simple_struct.png
new file mode 100644
index 000000000..973fa35e8
Binary files /dev/null and b/docs/benchmarks/rust/simple_struct.png differ
diff --git a/docs/benchmarks/rust/system_data.png 
b/docs/benchmarks/rust/system_data.png
new file mode 100644
index 000000000..330aa6b52
Binary files /dev/null and b/docs/benchmarks/rust/system_data.png differ
diff --git a/rust/benches/README.md b/rust/benches/README.md
index 0fd64f542..74435ae5e 100644
--- a/rust/benches/README.md
+++ b/rust/benches/README.md
@@ -1,3 +1,122 @@
+## Performance Comparison Report
+
+_Generated on 2025-10-26 18:36:41_
+
+How to generate performance report:
+
+```bash
+cd rust/benches
+cargo bench 2>&1 | tee cargo_bench.log
+python benchmark_report.py --log-file cargo_bench.log 
--output-dir=report_output
+```
+
+### Hardware & OS Info
+
+| Key                  | Value         |
+| -------------------- | ------------- |
+| OS                   | Darwin 24.5.0 |
+| Machine              | arm64         |
+| Processor            | arm           |
+| CPU Cores (Physical) | 12            |
+| CPU Cores (Logical)  | 12            |
+| Total RAM (GB)       | 48.0          |
+
+### Benchmark Plots
+
+**company**
+
+<p align="center">
+<img src="../../docs/benchmarks/rust/company.png" width="90%">
+</p>
+
+**ecommerce_data**
+
+<p align="center">
+<img src="../../docs/benchmarks/rust/ecommerce_data.png" width="90%">
+</p>
+
+**person**
+
+<p align="center">
+<img src="../../docs/benchmarks/rust/person.png" width="90%">
+</p>
+
+**simple_list**
+
+<p align="center">
+<img src="../../docs/benchmarks/rust/simple_list.png" width="90%">
+</p>
+
+**simple_map**
+
+<p align="center">
+<img src="../../docs/benchmarks/rust/simple_map.png" width="90%">
+</p>
+
+**simple_struct**
+
+<p align="center">
+<img src="../../docs/benchmarks/rust/simple_struct.png" width="90%">
+</p>
+
+**system_data**
+
+<p align="center">
+<img src="../../docs/benchmarks/rust/system_data.png" width="90%">
+</p>
+
+### Serialize Results (sorted by fastest TPS)
+
+| Datatype       | Size   | Operation | Fory TPS   | JSON TPS   | Protobuf TPS 
| Fastest |
+| -------------- | ------ | --------- | ---------- | ---------- | ------------ 
| ------- |
+| simple_struct  | small  | serialize | 35,729,598 | 10,167,045 | 8,633,342    
| fory    |
+| simple_struct  | medium | serialize | 34,988,279 | 9,737,098  | 6,433,350    
| fory    |
+| simple_struct  | large  | serialize | 31,801,558 | 4,545,041  | 7,420,049    
| fory    |
+| simple_list    | small  | serialize | 27,726,945 | 4,874,957  | 4,643,172    
| fory    |
+| simple_map     | small  | serialize | 22,862,369 | 3,888,025  | 2,695,999    
| fory    |
+| person         | small  | serialize | 13,632,522 | 1,345,189  | 1,475,035    
| fory    |
+| company        | small  | serialize | 10,063,906 | 761,673    | 896,620      
| fory    |
+| system_data    | small  | serialize | 5,382,131  | 468,033    | 569,930      
| fory    |
+| simple_list    | medium | serialize | 4,770,765  | 401,558    | 397,551      
| fory    |
+| person         | medium | serialize | 3,839,656  | 337,610    | 369,031      
| fory    |
+| ecommerce_data | small  | serialize | 2,350,729  | 206,262    | 256,970      
| fory    |
+| simple_map     | medium | serialize | 2,128,973  | 204,319    | 193,132      
| fory    |
+| person         | large  | serialize | 907,853    | 79,631     | 91,408       
| fory    |
+| simple_list    | large  | serialize | 606,061    | 41,061     | 44,565       
| fory    |
+| company        | medium | serialize | 412,507    | 33,835     | 37,590       
| fory    |
+| simple_map     | large  | serialize | 177,847    | 18,419     | 18,668       
| fory    |
+| system_data    | medium | serialize | 174,240    | 11,896     | 14,753       
| fory    |
+| ecommerce_data | medium | serialize | 59,977     | 4,699      | 5,242        
| fory    |
+| system_data    | large  | serialize | 10,671     | 876        | 1,040        
| fory    |
+| company        | large  | serialize | 9,183      | 793        | 880          
| fory    |
+| ecommerce_data | large  | serialize | 3,727      | 266        | 295          
| fory    |
+
+### Deserialize Results (sorted by fastest TPS)
+
+| Datatype       | Size   | Operation   | Fory TPS   | JSON TPS   | Protobuf 
TPS | Fastest |
+| -------------- | ------ | ----------- | ---------- | ---------- | 
------------ | ------- |
+| simple_struct  | small  | deserialize | 31,476,235 | 12,948,168 | 28,280,543 
  | fory    |
+| simple_struct  | medium | deserialize | 30,077,902 | 10,431,118 | 23,012,841 
  | fory    |
+| simple_struct  | large  | deserialize | 28,201,585 | 8,955,759  | 23,528,858 
  | fory    |
+| simple_list    | small  | deserialize | 6,129,329  | 3,599,582  | 4,429,286  
  | fory    |
+| simple_map     | small  | deserialize | 3,686,364  | 3,090,426  | 3,477,051  
  | fory    |
+| person         | small  | deserialize | 1,924,372  | 1,214,388  | 1,675,631  
  | fory    |
+| company        | small  | deserialize | 1,145,593  | 718,597    | 917,431    
  | fory    |
+| system_data    | small  | deserialize | 644,870    | 421,106    | 549,209    
  | fory    |
+| simple_list    | medium | deserialize | 460,745    | 305,409    | 337,336    
  | fory    |
+| person         | medium | deserialize | 371,016    | 265,280    | 266,333    
  | fory    |
+| ecommerce_data | small  | deserialize | 278,427    | 183,237    | 241,109    
  | fory    |
+| simple_map     | medium | deserialize | 171,774    | 126,638    | 119,323    
  | fory    |
+| person         | large  | deserialize | 84,839     | 63,975     | 61,820     
  | fory    |
+| simple_list    | large  | deserialize | 54,348     | 33,962     | 38,776     
  | fory    |
+| company        | medium | deserialize | 35,195     | 24,474     | 25,057     
  | fory    |
+| simple_map     | large  | deserialize | 16,501     | 10,920     | 10,853     
  | fory    |
+| system_data    | medium | deserialize | 14,322     | 9,205      | 10,565     
  | fory    |
+| ecommerce_data | medium | deserialize | 5,622      | 3,820      | 4,249      
  | fory    |
+| system_data    | large  | deserialize | 961        | 634        | 706        
  | fory    |
+| company        | large  | deserialize | 836        | 623        | 623        
  | fory    |
+| ecommerce_data | large  | deserialize | 298        | 204        | 217        
  | fory    |
+
 ## How to generate flamegraph
 
 ```bash
diff --git a/rust/benches/benchmark_report.py b/rust/benches/benchmark_report.py
new file mode 100644
index 000000000..e9530a016
--- /dev/null
+++ b/rust/benches/benchmark_report.py
@@ -0,0 +1,226 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import os
+import re
+import platform
+import psutil
+import argparse
+import matplotlib.pyplot as plt
+import numpy as np
+from collections import defaultdict
+from datetime import datetime
+
+# === Colors ===
+FORY_COLOR = "#FF6f01"  # Orange for Fory
+JSON_COLOR = "#55BCC2"  # Teal for JSON
+PROTOBUF_COLOR = (1, 0.84, 0.66)  # Light gold for Protobuf
+
+# === Regex to extract benchmark results ===
+bench_re = re.compile(
+    
r"Benchmarking\s+([\w_]+)/([\w]+)_(serialize|deserialize)/(\w+).*?time:\s+\[([\d\.]+)\s*([µ\w]+)",
+    re.DOTALL,
+)
+UNIT_TO_SEC = {"ns": 1e-9, "µs": 1e-6, "us": 1e-6, "ms": 1e-3, "s": 1.0}
+
+# === Parse arguments ===
+parser = argparse.ArgumentParser(
+    description="Plot Cargo Bench stats and generate Markdown report"
+)
+parser.add_argument("--log-file", default="cargo_bench.log", help="Benchmark 
log file")
+parser.add_argument(
+    "--output-dir", default="", help="Output directory for plots and report"
+)
+parser.add_argument(
+    "--plot-prefix", default="", help="Image path prefix in Markdown report"
+)
+args = parser.parse_args()
+
+# === Determine output directory ===
+if args.output_dir.strip():
+    output_dir = args.output_dir
+else:
+    output_dir = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
+
+os.makedirs(output_dir, exist_ok=True)
+
+# === Data structure ===
+data = defaultdict(lambda: defaultdict(lambda: defaultdict(dict)))
+
+# === Read and parse benchmark log ===
+with open(args.log_file, "r", encoding="utf-8") as f:
+    content = f.read()
+
+for match in bench_re.finditer(content):
+    struct, lib, op, size, time_val, unit = match.groups()
+    try:
+        time_val = float(time_val)
+    except ValueError:
+        continue
+    unit = unit.replace("μ", "µ")
+    if unit not in UNIT_TO_SEC:
+        continue
+    sec = time_val * UNIT_TO_SEC[unit]
+    tps = 1.0 / sec
+    data[struct][size][op][lib] = tps
+
+# === Sizes and operations ===
+sizes = ["small", "medium", "large"]
+ops = ["serialize", "deserialize"]
+
+
+# === Get system info ===
+def get_system_info():
+    try:
+        info = {
+            "OS": f"{platform.system()} {platform.release()}",
+            "Machine": platform.machine(),
+            "Processor": platform.processor() or "Unknown",
+            "CPU Cores (Physical)": psutil.cpu_count(logical=False),
+            "CPU Cores (Logical)": psutil.cpu_count(logical=True),
+            "Total RAM (GB)": round(psutil.virtual_memory().total / (1024**3), 
2),
+        }
+    except Exception as e:
+        info = {"Error gathering system info": str(e)}
+    return info
+
+
+system_info = get_system_info()
+
+serialize_rows = []
+deserialize_rows = []
+plot_images = []
+
+
+# === Plotting function ===
+def plot_datatype(ax, struct, size):
+    if size not in data[struct]:
+        ax.set_title(f"{size} {struct} - No Data")
+        ax.axis("off")
+        return
+    ops_present = [op for op in ops if op in data[struct][size]]
+    libs = sorted({lib for op in ops_present for lib in 
data[struct][size][op].keys()})
+    lib_order = [lib for lib in ["fory", "json", "protobuf"] if lib in libs] + 
[
+        lib for lib in libs if lib not in ["fory", "json", "protobuf"]
+    ]
+    x = np.arange(len(ops_present))
+    width = 0.8 / len(lib_order)
+    for i, lib in enumerate(lib_order):
+        color = None
+        if lib == "fory":
+            color = FORY_COLOR
+        elif lib == "json":
+            color = JSON_COLOR
+        elif lib == "protobuf":
+            color = PROTOBUF_COLOR
+        tps_vals = [data[struct][size][op].get(lib, 0) for op in ops_present]
+        ax.bar(x + i * width, tps_vals, width, label=lib, color=color)
+    ax.set_title(f"{size} {struct}")
+    ax.set_xticks(x + width * (len(lib_order) - 1) / 2)
+    ax.set_xticklabels(ops_present)
+    ax.grid(True, axis="y", linestyle="--", alpha=0.5)
+    ax.legend()
+    if size == "small":
+        ax.set_ylabel("TPS (ops/sec)")
+
+    # For Markdown tables
+    for op in ops_present:
+        f_tps = data[struct][size][op].get("fory", 0)
+        j_tps = data[struct][size][op].get("json", 0)
+        p_tps = data[struct][size][op].get("protobuf", 0)
+        fastest_lib, fastest_val = max(
+            [("fory", f_tps), ("json", j_tps), ("protobuf", p_tps)],
+            key=lambda kv: kv[1],
+        )
+        row = (struct, size, op, f_tps, j_tps, p_tps, fastest_lib, fastest_val)
+        if op == "serialize":
+            serialize_rows.append(row)
+        else:
+            deserialize_rows.append(row)
+
+
+# === Main plotting loop ===
+for struct in sorted(data.keys()):
+    fig, axes = plt.subplots(1, 3, figsize=(18, 5), sharey=False)  # No 
suptitle
+    for si, size in enumerate(sizes):
+        plot_datatype(axes[si], struct, size)
+    fig.tight_layout(rect=[0, 0, 1, 0.95])
+    plot_path = os.path.join(output_dir, f"{struct}.png")
+    plt.savefig(plot_path)
+    plot_images.append((struct, plot_path))
+    plt.close()
+
+# === Sort tables ===
+serialize_rows.sort(key=lambda r: r[7], reverse=True)
+deserialize_rows.sort(key=lambda r: r[7], reverse=True)
+
+# === Markdown report ===
+md_report = [
+    "## Performance Comparison Report\n",
+    f"_Generated on {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}_\n",
+    "How to generate performance report:\n",
+    "```bash\n",
+    "cd rust/benches\n",
+    "cargo bench 2>&1 | tee cargo_bench.log\n",
+    "python benchmark_report.py --log-file cargo_bench.log 
--output-dir=report_output\n",
+    "```\n",
+    "\n### Hardware & OS Info\n",
+    "| Key | Value |\n",
+    "|-----|-------|\n",
+]
+for k, v in system_info.items():
+    md_report.append(f"| {k} | {v} |\n")
+
+md_report.append("\n### Benchmark Plots\n")
+for struct, img in plot_images:
+    img_filename = os.path.basename(img)
+    img_path_report = args.plot_prefix + img_filename
+    md_report.append(f"\n**{struct}**\n\n")
+    md_report.append(
+        f'<p align="center">\n<img src="{img_path_report}" 
width="90%">\n</p>\n'
+    )
+
+
+def table_section(title, rows):
+    md = [f"\n### {title}\n"]
+    md.append(
+        "| Datatype | Size | Operation | Fory TPS | JSON TPS | Protobuf TPS | 
Fastest |\n"
+    )
+    md.append(
+        
"|----------|------|-----------|----------|----------|--------------|---------|\n"
+    )
+    for struct, size, op, f_tps, j_tps, p_tps, fastest_lib, fastest_val in 
rows:
+        md.append(
+            f"| {struct} | {size} | {op} | {f_tps:,.0f} | {j_tps:,.0f} | 
{p_tps:,.0f} | {fastest_lib} |\n"
+        )
+    return md
+
+
+md_report.extend(
+    table_section("Serialize Results (sorted by fastest TPS)", serialize_rows)
+)
+md_report.extend(
+    table_section("Deserialize Results (sorted by fastest TPS)", 
deserialize_rows)
+)
+
+# === Save Markdown ===
+report_path = os.path.join(output_dir, "README.md")
+with open(report_path, "w", encoding="utf-8") as f:
+    f.writelines(md_report)
+
+print(f"✅ Plots saved in: {output_dir}")
+print(f"📄 Markdown report generated at: {report_path}")


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

Reply via email to