Skip to content
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

Improve performance #39

Closed
naomijub opened this issue Aug 28, 2020 · 4 comments
Closed

Improve performance #39

naomijub opened this issue Aug 28, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request parse

Comments

@naomijub
Copy link
Collaborator

naomijub commented Aug 28, 2020

By not using replace we could improve performance to somewhere around 25µs. Currently the parse performance is around 140µs:

use std::time::{Instant};
use edn_rs;
use std::str::FromStr;

fn main() {
    let edn = edn_str();

    let start = Instant::now();
    let value = edn_rs::Edn::from_str(&edn);
    let duration = start.elapsed();

    if value.is_ok() {
        println!("Time elapsed in edn_rs::from_str is: {:?}", duration);

        let start_nav = Instant::now();
        let role = value.unwrap()[":associates"][0][":role"].clone();
        let duration_nav = start_nav.elapsed();

        println!("Time elapsed to navigate to role_0 \"{}\": {:?}", role, duration_nav);
    } else {
        println!("Parse failed. Duration {:?}", duration);
    }
}

fn edn_str() -> String {
    "{
        :type :human
        :first-name \"bench\"
        :last-name \"mark\"
        :age 13
        :version 0.13
        :associates [
            {
                :name :julia
                :role :adm
            }
            {
                :name :otavio
                :role :contributor
            }
            {
                :name :juxt
                :role :great-ideas
            }
        ]
    }".to_string()
}
@naomijub
Copy link
Collaborator Author

@otaviopace

@naomijub naomijub assigned naomijub and evaporei and unassigned naomijub Aug 28, 2020
@evaporei
Copy link
Collaborator

I will probably use parser combinators https://github.com/Geal/nom

@naomijub naomijub added enhancement New feature or request parse labels Aug 28, 2020
@naomijub
Copy link
Collaborator Author

naomijub commented Aug 28, 2020

Considering bench tool Criterion we got:

Benchmarking parse: Collecting 100 samples in estimated 5.1256 s (172k iteration                                                                              
parse                   time:   [29.361 us 29.447 us 29.541 us]
Found 7 outliers among 100 measurements (7.00%)
  2 (2.00%) low mild
  5 (5.00%) high severe

which can be improved to 5~7us

https://github.com/naomijub/edn-duration-benchmark/tree/master/criterion-parse-rs

@naomijub
Copy link
Collaborator Author

naomijub commented Sep 1, 2020

Current benchmark is around 13us:
#40

@naomijub naomijub closed this as completed Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request parse
Projects
None yet
Development

No branches or pull requests

2 participants