P
paululvinius
Hi!
Testing som Linq-expressions and tried to measure performance and
compare it to pre-Linq programming.
The folloing two methods are functional equal but the non-Linq one is
twice as fast.
public List<ConferenceRoom> OldWay(int minimumSeatingCapacity)
{
List<ConferenceRoom> availableRooms = new List<ConferenceRoom>();
foreach (ConferenceRoom room in rooms)
{
if (room.SeatingCapacity >= minimumSeatingCapacity)
availableRooms.Add(room);
}
return availableRooms;
}
public List<ConferenceRoom> NewWay(int minimumSeatingCapacity)
{
return (from room in rooms
where room.SeatingCapacity >= minimumSeatingCapacity
select room).ToList();
}
PS.
Just did a plain and simple:
DateTime start = DateTime.Now;
for (int i = 0; i < 1000000; i++)
rooms.OldWay(8);
Console.WriteLine((DateTime.Now - start).Ticks);
....to mesaure the performance (Did repeate the test over and over).
Results:
Non-Linq: ca. 6 300 000 ticks
Linq: ca. 3 100 000
Why is Linq slower?
Thanks
/Paul
Testing som Linq-expressions and tried to measure performance and
compare it to pre-Linq programming.
The folloing two methods are functional equal but the non-Linq one is
twice as fast.
public List<ConferenceRoom> OldWay(int minimumSeatingCapacity)
{
List<ConferenceRoom> availableRooms = new List<ConferenceRoom>();
foreach (ConferenceRoom room in rooms)
{
if (room.SeatingCapacity >= minimumSeatingCapacity)
availableRooms.Add(room);
}
return availableRooms;
}
public List<ConferenceRoom> NewWay(int minimumSeatingCapacity)
{
return (from room in rooms
where room.SeatingCapacity >= minimumSeatingCapacity
select room).ToList();
}
PS.
Just did a plain and simple:
DateTime start = DateTime.Now;
for (int i = 0; i < 1000000; i++)
rooms.OldWay(8);
Console.WriteLine((DateTime.Now - start).Ticks);
....to mesaure the performance (Did repeate the test over and over).
Results:
Non-Linq: ca. 6 300 000 ticks
Linq: ca. 3 100 000
Why is Linq slower?
Thanks
/Paul