C # data table batch processing

I have a data table with 20,000 rows, what is the best way to process 5,000 rows each time? I want to care about performance also

dataTable.AsEnumerable().Skip(x).Take(y)

is this method okay?

+4
source share
1 answer

This should work fine. The Linq skip method should run very fast. I suppose this will probably depend on how much content you have DataRows, but with 3 columns, I got almost instant calls:

        DataTable table = TwentyKRows();
        for (int i = 0; i < 4; i++)
        {
            DateTime before = DateTime.Now;
            var test = table.AsEnumerable().Skip(5000 * i).Take(5000);
            DateTime after = DateTime.Now;

            TimeSpan ts = after - before;
            Console.WriteLine(ts.ToString());
        }

Output:

00:00:00.0099991
00:00:00
00:00:00
00:00:00
-1
source

Source: https://habr.com/ru/post/1618530/


All Articles