What's faster: DateDifference or a straight comparison

T

Thomas V

Hi,

I was wondering which of two comparisons would be best to use. As far
is I can tell both would yield the same result.

Statement 1:
-----------------------
If Assignment1.Finish = Assignment2.Start
And Assignment1.ResourceName = Assignment2.ResourceName Then
[some code]
End If


Statement 2:
-----------------------
If DateDifference(Assignment1.Finish, Assignment2.Start) = 0
And Assignment1.ResourceName = Assignment2.ResourceName Then
[some code]
End If

Thanks.
Thomas V.
 
J

John

Thomas V said:
Hi,

I was wondering which of two comparisons would be best to use. As far
is I can tell both would yield the same result.

Statement 1:
-----------------------
If Assignment1.Finish = Assignment2.Start
And Assignment1.ResourceName = Assignment2.ResourceName Then
[some code]
End If


Statement 2:
-----------------------
If DateDifference(Assignment1.Finish, Assignment2.Start) = 0
And Assignment1.ResourceName = Assignment2.ResourceName Then
[some code]
End If

Thanks.
Thomas V.

Thomas,
When evaluating different approaches for writing code I try to analyze
problems that might occur (e.g. user action, variance in the data type,
etc.). I then pick an approach that works and addresses potential
problems. If I find that the selected approach executes to slowly, I
look for an alternate approach.

In your case I'd try both approaches on a real file and see if one works
better or faster than the other. Then chose accordingly.

Hope this helps.

John
Project MVP
 
J

Jack Dahlgren MVP

The only way to be sure which is faster is to do some testing.
I'd guess they are similar, but I don't think there is any published
information on how quickly different methods are executed.
The "some code" part is going to be where most of the time is spent anyway.
:)

-Jack Dahlgren


John said:
Thomas V said:
Hi,

I was wondering which of two comparisons would be best to use. As far
is I can tell both would yield the same result.

Statement 1:
-----------------------
If Assignment1.Finish = Assignment2.Start
And Assignment1.ResourceName = Assignment2.ResourceName Then
[some code]
End If


Statement 2:
-----------------------
If DateDifference(Assignment1.Finish, Assignment2.Start) = 0
And Assignment1.ResourceName = Assignment2.ResourceName Then
[some code]
End If

Thanks.
Thomas V.

Thomas,
When evaluating different approaches for writing code I try to analyze
problems that might occur (e.g. user action, variance in the data type,
etc.). I then pick an approach that works and addresses potential
problems. If I find that the selected approach executes to slowly, I
look for an alternate approach.

In your case I'd try both approaches on a real file and see if one works
better or faster than the other. Then chose accordingly.

Hope this helps.

John
Project MVP
 
R

Rod Gill

If there isn't much difference in performance (you only need to worry about
statements in a loop that runs many times) then use the version that is
easiest to understand as this will be quicker, easier and cheaper to
maintain.

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com



Jack Dahlgren MVP said:
The only way to be sure which is faster is to do some testing.
I'd guess they are similar, but I don't think there is any published
information on how quickly different methods are executed.
The "some code" part is going to be where most of the time is spent
anyway. :)

-Jack Dahlgren


John said:
Thomas V said:
Hi,

I was wondering which of two comparisons would be best to use. As far
is I can tell both would yield the same result.

Statement 1:
-----------------------
If Assignment1.Finish = Assignment2.Start
And Assignment1.ResourceName = Assignment2.ResourceName Then
[some code]
End If


Statement 2:
-----------------------
If DateDifference(Assignment1.Finish, Assignment2.Start) = 0
And Assignment1.ResourceName = Assignment2.ResourceName Then
[some code]
End If

Thanks.
Thomas V.

Thomas,
When evaluating different approaches for writing code I try to analyze
problems that might occur (e.g. user action, variance in the data type,
etc.). I then pick an approach that works and addresses potential
problems. If I find that the selected approach executes to slowly, I
look for an alternate approach.

In your case I'd try both approaches on a real file and see if one works
better or faster than the other. Then chose accordingly.

Hope this helps.

John
Project MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top