Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27214

Testing, Testing! Putting LINQ Through The Wringer

$
0
0
So I did these preliminary tests using a 2.6MB text file with 240000 entries length 2 to 20, selecting the 13,000 + entries of length 5.

1-3 used System.IO.File.ReadAllLines to populate array (words), 4 -5 used this streaming function ...

vb.net Code:
  1. Public Iterator Function StreamAllLines(path As String) As IEnumerable(Of String)
  2.         Using fileStream = New System.IO.StreamReader(path)
  3.             Dim line As String = fileStream.ReadLine()
  4.             Do While line <> Nothing
  5.                 Yield line
  6.                 line = fileStream.ReadLine()
  7.             Loop
  8.         End Using
  9.     End Function

1)
vb.net Code:
  1. For Each l In words
  2.                 If l.Length = 5 Then lst.Add(l)
  3.             Next

2)
vb.net Code:
  1. lst = (From x In words Where x.Length = 5).ToList

3)
vb.net Code:
  1. lst = Array.FindAll(words, (Function(x) x.Length = 5)).ToList

4)
vb.net Code:
  1. For Each l In StreamAllLines(filename)
  2.                 If l.Length = 5 Then lst.Add(l)
  3.             Next

5)
vb.net Code:
  1. lst = (From x In StreamAllLines(filename) Where x.Length = 5).ToList

6)
vb.net Code:
  1. lst = Array.FindAll(StreamAllLines(filename).ToArray, (Function(x) x.Length = 5)).ToList


I'll give a little while for people to stick their necks out and air their pet theories on which test did best in terms of speed, CPU load, and memory consumption and then I'll reveal the results.

At some point I'll do similar tests with rather more complex search criteria.

Viewing all articles
Browse latest Browse all 27214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>