Structs: pattern matching on nil values

Ahh, I think I was thinking about lists (as lists are the default ‘string’ type in erlang):

##### With input binary #####
Name                ips        average  deviation         median         99th %
guard_top       34.09 K       29.34 μs    ±74.54%          28 μs          45 μs
guard_bot       30.61 K       32.67 μs    ±74.42%          31 μs          48 μs
match_bot       22.81 K       43.85 μs    ±35.95%          41 μs          78 μs
match_top       22.38 K       44.69 μs    ±38.02%          43 μs          67 μs

Comparison: 
guard_top       34.09 K
guard_bot       30.61 K - 1.11x slower
match_bot       22.81 K - 1.49x slower
match_top       22.38 K - 1.52x slower

##### With input list #####
Name                ips        average  deviation         median         99th %
match_bot       34.39 K       29.08 μs    ±65.78%          28 μs          41 μs
guard_top       34.24 K       29.21 μs    ±54.19%          28 μs          45 μs
match_top       31.49 K       31.75 μs    ±61.61%          31 μs          46 μs
guard_bot       31.25 K       32.00 μs    ±57.29%          31 μs          49 μs

Comparison: 
match_bot       34.39 K
guard_top       34.24 K - 1.00x slower
match_top       31.49 K - 1.09x slower
guard_bot       31.25 K - 1.10x slower

##### With input not binary #####
Name                ips        average  deviation         median         99th %
guard_bot       31.18 K       32.07 μs    ±63.11%          31 μs          44 μs
guard_top       31.15 K       32.10 μs    ±58.90%          30 μs          50 μs
match_bot       29.16 K       34.30 μs    ±38.15%          33 μs          49 μs
match_top       27.41 K       36.48 μs    ±36.63%          35 μs          52 μs

Comparison: 
guard_bot       31.18 K
guard_top       31.15 K - 1.00x slower
match_bot       29.16 K - 1.07x slower
match_top       27.41 K - 1.14x slower

Substantial performance difference on binaries though (a good 50% slower for match contexts)! And of course the list test is faster than the binary test regardless of how it is done (the BEAM is built for lists instead of binaries when processing them out). ^.^

EDIT: The code is about the same is @michalmuskala’s except the count is increased to 1000 to prevent fast function warnings and I added some tuple cases to each set (unmatched in all cases) with the string/list test being at the top or bottom of the tuple matchers as per the test name.