-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introducing serde for benchmarking #41
Open
FranciscoThiesen
wants to merge
4
commits into
main
Choose a base branch
from
introducing_serde_for_benchmarking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d9aade6
Adding initial serde file for benchmarking. Should definitely get a r…
FranciscoThiesen 60fef62
Adding serde code needed to make it work on my mac
FranciscoThiesen b081be7
Removing unnecessary file
FranciscoThiesen 46e7cdb
Removing unnecessary additions
FranciscoThiesen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[target.aarch64-apple-darwin] | ||
rustflags = [ | ||
"-C", "link-arg=-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib", | ||
"-C", "link-arg=-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "serde-benchmark" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
extern crate serde; | ||
extern crate serde_json; | ||
|
||
use std::fs; | ||
use serde::{Serialize, Deserialize}; | ||
use std::time::Instant; | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Metadata { | ||
result_type: String, | ||
iso_language_code: String, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct User { | ||
id: i64, | ||
id_str: String, | ||
name: String, | ||
screen_name: String, | ||
location: String, | ||
description: String, | ||
url: Option<String>, | ||
protected: bool, | ||
followers_count: i64, | ||
friends_count: i64, | ||
listed_count: i64, | ||
created_at: String, | ||
favourites_count: i64, | ||
utc_offset: Option<i64>, | ||
time_zone: Option<String>, | ||
geo_enabled: bool, | ||
verified: bool, | ||
statuses_count: i64, | ||
lang: String, | ||
profile_background_color: String, | ||
profile_background_image_url: String, | ||
profile_background_image_url_https: String, | ||
profile_background_tile: bool, | ||
profile_image_url: String, | ||
profile_image_url_https: String, | ||
profile_banner_url: Option<String>, | ||
profile_link_color: String, | ||
profile_sidebar_border_color: String, | ||
profile_sidebar_fill_color: String, | ||
profile_text_color: String, | ||
profile_use_background_image: bool, | ||
default_profile: bool, | ||
default_profile_image: bool, | ||
following: bool, | ||
follow_request_sent: bool, | ||
notifications: bool, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Hashtag {} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Url {} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct UserMention { | ||
screen_name: String, | ||
name: String, | ||
id: i64, | ||
id_str: String, | ||
indices: Vec<i64>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Entities { | ||
hashtags: Vec<Hashtag>, | ||
urls: Vec<Url>, | ||
user_mentions: Vec<UserMention>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Status { | ||
metadata: Metadata, | ||
created_at: String, | ||
id: i64, | ||
id_str: String, | ||
text: String, | ||
source: String, | ||
truncated: bool, | ||
in_reply_to_status_id: Option<i64>, | ||
in_reply_to_status_id_str: Option<String>, | ||
in_reply_to_user_id: Option<i64>, | ||
in_reply_to_user_id_str: Option<String>, | ||
in_reply_to_screen_name: Option<String>, | ||
user: User, | ||
geo: Option<String>, | ||
coordinates: Option<String>, | ||
place: Option<String>, | ||
contributors: Option<String>, | ||
retweet_count: i64, | ||
favorite_count: i64, | ||
favorited: bool, | ||
retweeted: bool, | ||
entities: Entities, | ||
lang: String, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct TwitterData { | ||
statuses: Vec<Status>, | ||
} | ||
|
||
fn main() { | ||
// Read the JSON data from the file once | ||
let data = fs::read_to_string("/Users/random_person/Desktop/experimental_json_builder/benchmarks/src/data/twitter.json") | ||
.expect("Unable to read file"); | ||
|
||
// Deserialize the JSON data into a TwitterData object once | ||
let twitter_data: TwitterData = serde_json::from_str(&data) | ||
.expect("Unable to deserialize data"); | ||
|
||
let num_iterations = 500; | ||
let mut total_serialize_duration = 0.0; | ||
let mut output_volume = 0; | ||
|
||
for _ in 0..num_iterations { | ||
let start = Instant::now(); | ||
let serialized = serde_json::to_string(&twitter_data) | ||
.expect("Unable to serialize data"); | ||
let serialize_duration = start.elapsed().as_secs_f64(); | ||
total_serialize_duration += serialize_duration; | ||
|
||
output_volume += serialized.len(); | ||
} | ||
|
||
let avg_serialize_time = total_serialize_duration / num_iterations as f64; | ||
let throughput_mb_s = (output_volume as f64 / 1_000_000.0) / total_serialize_duration; | ||
|
||
println!("# volume: {} bytes", data.len()); | ||
println!("# output volume: {} bytes", output_volume); | ||
println!("# output volume per string: {:.1} bytes", output_volume as f64 / num_iterations as f64); | ||
println!("# number of inputs: {}", num_iterations); | ||
println!("Serialization:"); | ||
println!(" Avg time per operation: {:.6} s", avg_serialize_time); | ||
println!(" Throughput: {:.2} MB/s", throughput_mb_s); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm.... system-specific paths...