Skip to main content
added 44 characters in body
Source Link
Wayne
  • 103
  • 1
  • 6

I am using a function to compare over 100 variables inside of classes to each other an am curious if one method of comparing multiple condition statements is more efficient than another. I am currently considering one of these methods. I think the 'single If using And/Or' looks the cleanest but performance is more important. (my code is VB.Net)

Multiple ElseIf

If Not ClassA.num = ClassB.num Then
    Return False
ElseIf Not ClassA.str = ClassB.str Then
    Return False
Else : Return True
End If

Single If using And/Or

If Not ClassA.num = ClassB.num Or
   Not ClassA.str = ClassB.str Then
       Return False
Else : Return True
End If

Nested If

If Not ClassA.num = ClassB.num Then
    If Not ClassA.str = ClassB.str Then
        Return FalseTrue
    End If
End If
Return TrueFalse

Edit: Changed second code snippet from And to Or

Edit 2: Changed third snippet from If Not to If

I am using a function to compare over 100 variables inside of classes to each other an am curious if one method of comparing multiple condition statements is more efficient than another. I am currently considering one of these methods. I think the 'single If using And/Or' looks the cleanest but performance is more important. (my code is VB.Net)

Multiple ElseIf

If Not ClassA.num = ClassB.num Then
    Return False
ElseIf Not ClassA.str = ClassB.str Then
    Return False
Else : Return True
End If

Single If using And/Or

If Not ClassA.num = ClassB.num Or
   Not ClassA.str = ClassB.str Then
       Return False
Else : Return True
End If

Nested If

If Not ClassA.num = ClassB.num Then
    If Not ClassA.str = ClassB.str Then
        Return False
    End If
End If
Return True

Edit: Changed second code snippet from And to Or

I am using a function to compare over 100 variables inside of classes to each other an am curious if one method of comparing multiple condition statements is more efficient than another. I am currently considering one of these methods. I think the 'single If using And/Or' looks the cleanest but performance is more important. (my code is VB.Net)

Multiple ElseIf

If Not ClassA.num = ClassB.num Then
    Return False
ElseIf Not ClassA.str = ClassB.str Then
    Return False
Else : Return True
End If

Single If using And/Or

If Not ClassA.num = ClassB.num Or
   Not ClassA.str = ClassB.str Then
       Return False
Else : Return True
End If

Nested If

If ClassA.num = ClassB.num Then
    If ClassA.str = ClassB.str Then
        Return True
    End If
End If
Return False

Edit: Changed second code snippet from And to Or

Edit 2: Changed third snippet from If Not to If

added 62 characters in body
Source Link
Wayne
  • 103
  • 1
  • 6

I am using a function to compare over 100 variables inside of classes to each other an am curious if one method of comparing multiple condition statements is more efficient than another. I am currently considering one of these methods. I think the 'single If using And'And/Or' looks the cleanest but performance is more important. (my code is VB.Net)

Multiple ElseIf

If Not ClassA.num = ClassB.num Then
    Return False
ElseIf Not ClassA.str = ClassB.str Then
    Return False
Else : Return True
End If

Single If using And/Or

If Not ClassA.num = ClassB.num AndOr
   Not ClassA.str = ClassB.str Then
       Return False
Else : Return True
End If

Nested If

If Not ClassA.num = ClassB.num Then
    If Not ClassA.str = ClassB.str Then
        Return False
    End If
End If
Return True

Edit: Changed second code snippet from And to Or

I am using a function to compare over 100 variables inside of classes to each other an am curious if one method of comparing multiple condition statements is more efficient than another. I am currently considering one of these methods. I think the 'single If using And' looks the cleanest but performance is more important. (my code is VB.Net)

Multiple ElseIf

If Not ClassA.num = ClassB.num Then
    Return False
ElseIf Not ClassA.str = ClassB.str Then
    Return False
Else : Return True
End If

Single If using And

If Not ClassA.num = ClassB.num And
   Not ClassA.str = ClassB.str Then
       Return False
Else : Return True
End If

Nested If

If Not ClassA.num = ClassB.num Then
    If Not ClassA.str = ClassB.str Then
        Return False
    End If
End If
Return True

I am using a function to compare over 100 variables inside of classes to each other an am curious if one method of comparing multiple condition statements is more efficient than another. I am currently considering one of these methods. I think the 'single If using And/Or' looks the cleanest but performance is more important. (my code is VB.Net)

Multiple ElseIf

If Not ClassA.num = ClassB.num Then
    Return False
ElseIf Not ClassA.str = ClassB.str Then
    Return False
Else : Return True
End If

Single If using And/Or

If Not ClassA.num = ClassB.num Or
   Not ClassA.str = ClassB.str Then
       Return False
Else : Return True
End If

Nested If

If Not ClassA.num = ClassB.num Then
    If Not ClassA.str = ClassB.str Then
        Return False
    End If
End If
Return True

Edit: Changed second code snippet from And to Or

language seems important for this question
Link
Mike Partridge
  • 6.7k
  • 1
  • 28
  • 42
Source Link
Wayne
  • 103
  • 1
  • 6
Loading