I get these results using racket 8.10 in DrRacket on my machine:
destructuring match:
cpu time: 67 real time: 71 gc time: 2
cond with predicates:
cpu time: 1131 real time: 1151 gc time: 8
match with predicates:
cpu time: 790 real time: 791 gc time: 5
generic interface:
cpu time: 946 real time: 960 gc time: 5
If I make all of the structs #:transparent
, I get these results in DrRacket:
destructuring match:
cpu time: 63 real time: 71 gc time: 2
cond with predicates:
cpu time: 413 real time: 438 gc time: 5
match with predicates:
cpu time: 262 real time: 283 gc time: 4
generic interface:
cpu time: 398 real time: 424 gc time: 4
If I make them all #:authentic
, I get this in DrRacket:
destructuring match:
cpu time: 59 real time: 68 gc time: 2
cond with predicates:
cpu time: 1126 real time: 1170 gc time: 7
match with predicates:
cpu time: 758 real time: 765 gc time: 4
generic interface:
cpu time: 937 real time: 944 gc time: 4
If I make them all #:transparent
and #:authentic
, I get this in DrRacket:
destructuring match:
cpu time: 59 real time: 61 gc time: 2
cond with predicates:
cpu time: 1123 real time: 1184 gc time: 7
match with predicates:
cpu time: 768 real time: 775 gc time: 4
generic interface:
cpu time: 965 real time: 981 gc time: 5
Command line:
destructuring match:
cpu time: 32 real time: 33 gc time: 0
cond with predicates:
cpu time: 35 real time: 36 gc time: 0
match with predicates:
cpu time: 35 real time: 36 gc time: 0
generic interface:
cpu time: 148 real time: 151 gc time: 0
Command line with #:transparent
:
destructuring match:
cpu time: 33 real time: 34 gc time: 0
cond with predicates:
cpu time: 36 real time: 37 gc time: 0
match with predicates:
cpu time: 35 real time: 36 gc time: 0
generic interface:
cpu time: 148 real time: 150 gc time: 0
Command line with #:authentic
:
destructuring match:
cpu time: 23 real time: 24 gc time: 0
cond with predicates:
cpu time: 23 real time: 24 gc time: 0
match with predicates:
cpu time: 23 real time: 24 gc time: 0
generic interface:
cpu time: 149 real time: 153 gc time: 0
Command line with #:transparent
and #:authentic
:
destructuring match:
cpu time: 22 real time: 23 gc time: 0
cond with predicates:
cpu time: 22 real time: 23 gc time: 0
match with predicates:
cpu time: 22 real time: 23 gc time: 0
generic interface:
cpu time: 145 real time: 148 gc time: 0
In summary, in DrRacket:
- Destructuring pattern matches are consistently the fastest by a huge margin.
- Destructuring pattern matches are slightly faster on transparent structs, and slightly faster still on authentic structs.
- Generic interfaces are around 15x slower than destructuring, unless the struct is transparent and not authentic, in which case they're only about 6x slower.
- Directly calling the predicates and accessors is very slow, even compared to generic interfaces, for unclear reasons.
Some of this doesn't make much sense to me. Opinions and explanations welcome.
In the command line, things are much more as expected. All of the non-generic interface variants perform about the same, and making the struct transparent doesn't make much of a difference for them but making it authentic makes it slightly faster. Generic interfaces are about 5x slower and have no speedup on authentic or transparent structs.