Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adding benchmarks for macro rules in match statements #23

Merged
merged 1 commit into from
Oct 23, 2020

Conversation

sffc
Copy link
Collaborator

@sffc sffc commented Aug 26, 2020

Microbenchmarks for #22

To run these benchmarks:

$ cd macros
$ cargo +nightly bench

}

macro_rules! gen_match {
($TinyType:ident, [$( ($item:ident, $tiny:expr) ),*]) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Manishearth @zbraniecki @filmil Is there a macro_rules! definition here where I can call the sub-macro like tinystr4! instead of repeating the strings, once as an identifier and once as a TinyStr? In other words, at the call site, instead of

    gen_match!(TinyStr4, [
        (US, tinystr4!("US")),
        (GB, tinystr4!("GB")),
        (AR, tinystr4!("AR"))
    ]);

how can I make it

    gen_match!(TinyStr4, tinystr4!, [
        US,
        GB,
        AR
    ]);

@sffc
Copy link
Collaborator Author

sffc commented Oct 22, 2020

I rebased this branch against master.

The results still show a substantial speed improvement for matching on TinyStr instead of &str:

sffc@sffc-glaptop:~/projects/tinystr$ cargo bench match
    Finished bench [optimized] target(s) in 0.05s
     Running target/release/deps/tinystr-56c3c30eb67dc973

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 3 filtered out

     Running target/release/deps/construct-2ba8dab4959a2cf1
     Running target/release/deps/match-fabb5d3621ad3e6c
match str 4             time:   [141.21 ns 142.69 ns 144.60 ns]                        
Found 14 outliers among 100 measurements (14.00%)
  4 (4.00%) high mild
  10 (10.00%) high severe

match tiny 4            time:   [37.423 ns 37.714 ns 38.045 ns]                          
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild

match str 8             time:   [98.567 ns 98.832 ns 99.149 ns]                        
Found 13 outliers among 100 measurements (13.00%)
  8 (8.00%) high mild
  5 (5.00%) high severe

match tiny 8            time:   [42.638 ns 42.788 ns 42.968 ns]                          
Found 5 outliers among 100 measurements (5.00%)
  3 (3.00%) high mild
  2 (2.00%) high severe

match str 16            time:   [82.722 ns 83.194 ns 83.830 ns]                         
Found 9 outliers among 100 measurements (9.00%)
  5 (5.00%) high mild
  4 (4.00%) high severe

match tiny 16           time:   [46.771 ns 46.944 ns 47.128 ns]                           
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) high mild
  2 (2.00%) high severe

     Running target/release/deps/tinystr-36a62aaa4f4b4caa

Copy link
Owner

@zbraniecki zbraniecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! Thank you!

@sffc sffc merged commit f52ad26 into zbraniecki:master Oct 23, 2020
@sffc sffc deleted the macro-bench branch October 23, 2020 04:11
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants