dtolnay / proc-macro-workshop

Learn to write Rust procedural macros  [Rust Latam conference, Montevideo Uruguay, March 2019]
Apache License 2.0
4.13k stars 1.04k forks source link

Add benchmarks for bitfields #18

Closed Robbepop closed 5 years ago

Robbepop commented 5 years ago

This adds benchmarks for the bitfield implementation.

Compares the performance of getters and setters generated by the macro with the performance of a handwritten and hard coded implementation for the same spec.

Useful

Note

Benchmarks

Below some benchmarks comparing the hand-written implementation of this PR with the macro-generated implementation of the bitfield implementation in my fork. The performance of both seem to be similar.

test generated::get_a   ... bench:          99 ns/iter (+/- 4)
test generated::get_b   ... bench:          98 ns/iter (+/- 4)
test generated::get_c   ... bench:          98 ns/iter (+/- 14)
test generated::get_d   ... bench:          97 ns/iter (+/- 2)
test generated::get_e   ... bench:          99 ns/iter (+/- 2)
test generated::set_a   ... bench:         481 ns/iter (+/- 19)
test generated::set_b   ... bench:         627 ns/iter (+/- 37)
test generated::set_c   ... bench:         507 ns/iter (+/- 35)
test generated::set_d   ... bench:         622 ns/iter (+/- 24)
test generated::set_e   ... bench:         459 ns/iter (+/- 16)
test handwritten::get_a ... bench:          99 ns/iter (+/- 3)
test handwritten::get_b ... bench:         102 ns/iter (+/- 14)
test handwritten::get_c ... bench:         102 ns/iter (+/- 8)
test handwritten::get_d ... bench:         100 ns/iter (+/- 20)
test handwritten::get_e ... bench:          98 ns/iter (+/- 6)
test handwritten::set_a ... bench:         582 ns/iter (+/- 20)
test handwritten::set_b ... bench:         614 ns/iter (+/- 35)
test handwritten::set_c ... bench:         533 ns/iter (+/- 18)
test handwritten::set_d ... bench:         606 ns/iter (+/- 21)
test handwritten::set_e ... bench:         456 ns/iter (+/- 21)
Robbepop commented 5 years ago

Just added some tests to the benchmarks to assert that their implementations are actually correct and fixed some bugs while doing so.

You can invoke the benchmark tests with: cargo test --benches