It often happens that I'd like to know which of two or more alternative expressions (that should evaluate to the same value) is fastest. For example, below are three ways to define a function:
fooVersion1[x_]/; x > 0 := E^(-1/x); fooVersion1[x_] := 0; fooVersion2[x_] := If[x > 0, E^(-1/x), 0]; fooVersion3 = Function[x, If[x > 0, E^(-1/x), 0]];
(Granted, strictly speaking, these three versions are not completely equivalent, but at least, for all real scalars
fooVersion3[x] should evaluate to the same value.)
Is there a way to determine which one is fastest that is both simple and reasonably reliable?