Link to home
Start Free TrialLog in
Avatar of KaranGupta
KaranGupta

asked on

string comparison Vs DateTime comparison

Hi

Which is quicker

1. comparing 2 string variables
2. comparing 2 datetime variables.

How can I check that.
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

I used powershell to do  the timing and comparing datetime is faster (uses .net libraries)

$var1 = get-date
$var2 = Get-Date 
$var3 = "2012-12-01 12:01AM"
$var4 = "2012-12-02 12:02AM"
Measure-Command {if ($var1 -ne $var2) {}}
Measure-Command {if ($var3 -ne $var4) {}}

Open in new window

1690 tics vs 2623 ticks
Avatar of KaranGupta
KaranGupta

ASKER

Hi

Can you please post .net code because I am not aware of powershell technology? Can you also tell how you have measured these ticks?

Regards
Karan Gupta
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That is what I want. Thanks a lot