performance - vb.net Is it better to do multiple OrElse's, or a single check if Mod = 0 -
there 2 easy ways check whether month first of quarter.
the first way:
if month = 3 orelse month = 6 orelse month = 9 orelse month = 12 'do stuff end if
the second way:
if month mod 3 = 0 'do stuff end if
to me, both equally readable. though functionally different, long month known between 1 , 12 inclusive, same logic. way should used?
in worst case, if month = 12
, there 4 comparisons performed. doing modulus , 1 comparison faster (not it's significant performance difference)?
as davedoknjas stated in comments above, use method follows logic more clearly.
if logic determines must because month 3rd, 6th, 9th, or 12th month in year, use:
if month = 3 orelse month = 6 orelse month = 9 orelse month = 12 'do stuff end if
but, on other hand, if need because number of month evenly divisible 3, use:
if month mod 3 = 0 'do stuff end if
the difference in performance miniscule wouldn't noticeable. in end, both evaluate true
when need them to, it's down preference , deem logical , readable.
Comments
Post a Comment