rust-bakery / parser_benchmarks

Benchmarks for the nom, the Rust parser combinators library
123 stars 20 forks source link

Add an optimized http parser using the same ideas as nom-optimized #18

Closed Marwes closed 6 years ago

Marwes commented 6 years ago

Since combine is a lot more reliant on inlining and other optimizations the performance is subject to some variance between compiler versions and operating systems.

Old combine vs optimized combine

$ cargo benchcmp old new
 name                   old ns/iter         new ns/iter         diff ns/iter   diff %  speedup
 bigger_test            631,356 (169 MB/s)  45,201 (2364 MB/s)      -586,155  -92.84%  x 13.97
 httparse_example_test  2,706 (259 MB/s)    242 (2904 MB/s)           -2,464  -91.06%  x 11.18
 one_test               1,890 (153 MB/s)    132 (2204 MB/s)           -1,758  -93.02%  x 14.32
 small_test             132,478 (161 MB/s)  9,007 (2373 MB/s)       -123,471  -93.20%  x 14.71

Optimized combine vs optimized nom

$ cargo benchcmp ../combine-http/new nom
 name                   ../combine-http/new ns/iter  nom ns/iter         diff ns/iter  diff %  speedup
 bigger_test            45,201 (2364 MB/s)           44,337 (2410 MB/s)          -864  -1.91%   x 1.02
 httparse_example_test  242 (2904 MB/s)              219 (3210 MB/s)              -23  -9.50%   x 1.11
 one_test               132 (2204 MB/s)              120 (2425 MB/s)              -12  -9.09%   x 1.10
 small_test             9,007 (2373 MB/s)            8,765 (2439 MB/s)           -242  -2.69%   x 1.03

Normal combine vs normal nom

Combine does loop unrolling by default which nom doesn't and it also takes some hints from the optimized parser which pushes it ahead currently.

$ cargo benchcmp new ../nom-http/new
 name                   new ns/iter         ../nom-http/new ns/iter  diff ns/iter  diff %  speedup
 bigger_test            301,135 (354 MB/s)  454,767 (235 MB/s)            153,632  51.02%   x 0.66
 httparse_example_test  1,483 (474 MB/s)    2,005 (350 MB/s)                  522  35.20%   x 0.74
 one_test               1,002 (290 MB/s)    1,256 (231 MB/s)                  254  25.35%   x 0.80
 small_test             58,193 (367 MB/s)   98,445 (217 MB/s)              40,252  69.17%   x 0.59
Geal commented 6 years ago

sorry, I forgot to merge that, I'll measure everything again :)

Marwes commented 6 years ago

I forgot about it as well, so no worries :)