Wrote it from the phone so not at the time, have used a similar solution 
where at first the initial if was missing so different types with the same 
arguments returned true. Just did a benchmark with 3 cases, one with the 
literal function above (after fixing the missing ')'), one with n directly 
being the name and one with literal a.a==b.a checks, a has 5 random 
variables and b is its deepcopy.

julia> @time for i in 1:1000;a==b;end #with length
elapsed time: 0.001184089 seconds (96000 bytes allocated)

julia> @time for i in 1:1000;a==b;end #with for n in names
elapsed time: 0.000963879 seconds (96000 bytes allocated)

julia> @time for i in 1:1000;a==b;end #with explicit check
elapsed time: 0.000156515 seconds (0 bytes allocated)

Interestingly the length allocation does not have an impact. So according 
to this result for every second you spend writing an explicit == you can do 
a million generic checks. The difference becomes less pronounced with the 
random variables replaced by arrays with a thousand random variables:

julia> @time for i in 1:1000;a==b;end #generic
elapsed time: 0.013679254 seconds (496000 bytes allocated)

julia> @time for i in 1:1000;a==b;end #explicit
elapsed time: 0.012587005 seconds (400000 bytes allocated)

Reply via email to