Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions rust/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Cargo.lock
/target
**/generated
3 changes: 2 additions & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ members = [
"fory-core",
"fory",
"fory-derive",
"tests"
"tests",
"benches"
]

exclude = [
Expand Down
24 changes: 24 additions & 0 deletions rust/benches/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "fory-benchmarks"
version = "0.1.0"
edition = "2021"

[[bench]]
name = "serialization_bench"
path = "benches/serialization_bench.rs"
harness = false

[dependencies]
fory = { path = "../fory" }
fory-core = { path = "../fory-core" }
fory-derive = { path = "../fory-derive" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
chrono = { version = "0.4", features = ["serde"] }
prost = "0.12"
prost-types = "0.12"
rand = "0.8"
criterion = "0.5"

[build-dependencies]
prost-build = "0.12"
5 changes: 5 additions & 0 deletions rust/benches/benches/serialization_bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use criterion::{criterion_group, criterion_main};
use fory_benchmarks::run_serialization_benchmarks;

criterion_group!(benches, run_serialization_benchmarks);
criterion_main!(benches);
31 changes: 31 additions & 0 deletions rust/benches/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::path::Path;

fn main() {
println!("cargo:warning=Build script running");
println!("cargo:warning=OUT_DIR: {}", std::env::var("OUT_DIR").unwrap());

let proto_files = [
"proto/simple.proto",
"proto/medium.proto",
"proto/complex.proto",
"proto/realworld.proto",
];

for proto_file in &proto_files {
if Path::new(proto_file).exists() {
println!("cargo:rerun-if-changed={}", proto_file);
println!("cargo:warning=Found proto file: {}", proto_file);
} else {
println!("cargo:warning=Proto file not found: {}", proto_file);
}
}

let mut config = prost_build::Config::new();
// Don't set out_dir, use the default OUT_DIR

println!("cargo:warning=About to compile protobuf files");
config
.compile_protos(&proto_files, &["proto/"])
.expect("Failed to compile protobuf files");
println!("cargo:warning=Protobuf compilation completed");
}
46 changes: 46 additions & 0 deletions rust/benches/proto/complex.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
syntax = "proto3";

package complex;

import "google/protobuf/timestamp.proto";

message Product {
string id = 1;
string name = 2;
double price = 3;
repeated string categories = 4;
map<string, string> attributes = 5;
}

message OrderItem {
Product product = 1;
int32 quantity = 2;
double unit_price = 3;
map<string, string> customizations = 4;
}

message Customer {
string id = 1;
string name = 2;
string email = 3;
repeated string phone_numbers = 4;
map<string, string> preferences = 5;
google.protobuf.Timestamp member_since = 6;
}

message Order {
string id = 1;
Customer customer = 2;
repeated OrderItem items = 3;
double total_amount = 4;
string status = 5;
google.protobuf.Timestamp order_date = 6;
map<string, string> metadata = 7;
}

message ProtoECommerceData {
repeated Order orders = 1;
repeated Customer customers = 2;
repeated Product products = 3;
map<string, Order> order_lookup = 4;
}
28 changes: 28 additions & 0 deletions rust/benches/proto/medium.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
syntax = "proto3";

package medium;

import "google/protobuf/timestamp.proto";

message Address {
string street = 1;
string city = 2;
string country = 3;
string zip_code = 4;
}

message ProtoPerson {
string name = 1;
int32 age = 2;
Address address = 3;
repeated string hobbies = 4;
map<string, string> metadata = 5;
google.protobuf.Timestamp created_at = 6;
}

message ProtoCompany {
string name = 1;
repeated ProtoPerson employees = 2;
map<string, Address> offices = 3;
bool is_public = 4;
}
54 changes: 54 additions & 0 deletions rust/benches/proto/realworld.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
syntax = "proto3";

package realworld;

import "google/protobuf/timestamp.proto";

message LogLevel {
enum Level {
UNKNOWN = 0;
DEBUG = 1;
INFO = 2;
WARN = 3;
ERROR = 4;
FATAL = 5;
}
Level level = 1;
}

message LogEntry {
string id = 1;
LogLevel.Level level = 2;
string message = 3;
string service = 4;
google.protobuf.Timestamp timestamp = 5;
map<string, string> context = 6;
repeated string tags = 7;
double duration_ms = 8;
}

message UserProfile {
string user_id = 1;
string username = 2;
string email = 3;
map<string, string> preferences = 4;
repeated string permissions = 5;
google.protobuf.Timestamp last_login = 6;
bool is_active = 7;
}

message APIMetrics {
string endpoint = 1;
int64 request_count = 2;
double avg_response_time = 3;
int64 error_count = 4;
map<string, int64> status_codes = 5;
google.protobuf.Timestamp measured_at = 6;
}

message ProtoSystemData {
repeated LogEntry logs = 1;
repeated UserProfile users = 2;
repeated APIMetrics metrics = 3;
map<string, string> system_info = 4;
}
20 changes: 20 additions & 0 deletions rust/benches/proto/simple.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto3";

package simple;

message ProtoSimpleStruct {
int32 id = 1;
string name = 2;
bool active = 3;
double score = 4;
}

message ProtoSimpleList {
repeated int32 numbers = 1;
repeated string names = 2;
}

message ProtoSimpleMap {
map<string, int32> string_to_int = 1;
map<int32, string> int_to_string = 2;
}
Loading
Loading