Sorry Andre, I do not understand your point. Do you mean something like this ?
using System;
using Microsoft.SPOT;
using GHIElectronics.NETMF.Hardware;
namespace stringcomparison_benchmark
{
public class Program
{
public static void Main()
{
bool result1 = false;
bool result2 = false;
string[] s = new string[1000];
for(int i = 0;i < 1000;i++)
{
s[i] = "abcd";
}
while(true)
{
DateTime t1;
DateTime t2;
t1 = DateTime.Now;
for(int i = 0;i < 1000;i++)
{
if(s[i] == "abcd")
result1 = true;
else result1 = false;
if(s[i] == "efgh")
result2 = true;
else result2 = false;
}
t2 = DateTime.Now;
Debug.Print("Result1 = " + result1);
Debug.Print("Result2 = " + result2);
Debug.Print(" == in," + (t2 - t1).Ticks / 10 + ", micro seconds");
t1 = DateTime.Now;
for(int i = 0;i < 1000;i++)
{
if(s[i].Equals("abcd"))
result1 = true;
else result1 = false;
if(s[i].Equals("efgh"))
result2 = true;
else result2 = false;
}
t2 = DateTime.Now;
Debug.Print("Result1 = " + result1);
Debug.Print("Result2 = " + result2);
Debug.Print(" Equals in," + (t2 - t1).Ticks / 10 + ", micro seconds");
}
}
}
}
As you have already said, there’s no difference after modification:
== in,276817, micro seconds
Equals in,480472, micro seconds