Skip to content

System.IO.Directory.GetFiles with searchFilter is about 1000 times slower compared to .net framework #56464

@msneijders

Description

@msneijders

Description

See code below, System.IO.Directory.GetFiles is much slower in dotnet 5.0 compared to net 471.

using System;
using System.Diagnostics;
using System.Linq;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();

            for (int i = 0; i < 100; i++)
            {
                var files = System.IO.Directory.GetFiles(@"F:\pictures", "A14881*.jpg", System.IO.SearchOption.TopDirectoryOnly);
            }

            sw.Stop();

            Console.WriteLine(sw.Elapsed.ToString());
            // Folder size: 140.000 files -- 4 files matching searchFilter
            // net5.0: 3.3 seconds
            // net471: 0.0033 seconds (1000 times faster)

            Console.ReadLine();
        }
    }
}

Configuration

Windows 10 Pro

Regression?

Regression from net471

Data

        // Folder size: 140.000 files -- 4 files matching searchFilter
        // net5.0: 3.3 seconds
        // net471: 0.0033 seconds (1000 times faster)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions