dazinator / DotNet.Glob

A fast globbing library for .NET / .NETStandard applications. Outperforms Regex.
MIT License
363 stars 27 forks source link

Comparison with Microsoft.Extensions.FileSystemGlobbing #17

Closed cocowalla closed 6 years ago

cocowalla commented 7 years ago

Now that Microsoft has a globbing library, it would be useful to see a comparison of features and performance in the wiki.

dazinator commented 7 years ago

Yeah, I believe Microsoft's is fairly limited - I think it only supports wildcards (*). In terms of comparison of features, I don't think Microsoft currently compares. In terms of comparison of performance, I would suspect the same from looking at the code - not to say it performs badly but just not as optimised as dotnet.glob I suspect - however I could add some benchmarks for this - when I get some time. Or feel free to contribute some benchmarks yourself if you like, should be pretty straight forward as there are already some there you could copy!

dazinator commented 7 years ago

I have looked some more into the Microsoft FileSystem Globbing package.

It appears their implementation revolves around first creating a PatternMatacher which you can add multiple includes and excludes to:

  var matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher(System.StringComparison.OrdinalIgnoreCase);
                matcher.AddInclude("*.txt");

Once you have specified your include and exclude patterns, you then have to execute the pattern matcher.. However you can only execute it against a DirectoryInfoBase implementation.

var someDirectory = new DisposableDirectoryInfo();
var result =  matcher.Execute(someDirectory);
var matches = result.Files;

In other words, to test how efficient the glob pattern matching is, I'd have to have to create a mock directory, add some mock files, create a matcher and give it a single include pattern, i.e the glob pattern, and then execute it against the directory, and verify it returns me the matching file.

This is a bit higher level than DotNetGlob which directly matches a string, and returns true or false.

So I can do this, but the comparisons would be a little unfair as for microsofts implementation it has this extra fluff in the way.

I assume that internally, they must have somewhere the same kind of logic to simply evaluate whether the path string matches the pattern - but I can't see that they expose this - otherwise I could just test how effiecient that is versus DotNetGlob.

So, given the above, do you still think it is worth doing this comparison, or perhaps there is an alternative approach you would like me to compare - let me know.

dazinator commented 7 years ago

I guess what I could do.. Is compare Microsoft pattern matcher for returning the results, against, looping through an IDorectoryBase and calling DotNetGlob.IsMatch() on the files full path to get the same set of results. I think this would be a better test.

That would be interesting because if it's more efficient to iterate the files in the directory and call .IsMacth to collate the results, then there would be no reason to use PatternMatcher at all, as it's also more limited with the types of glob patterns it supports.

dazinator commented 6 years ago

I am going to close this because I won't have time to do this in the near term.

jozkee commented 4 years ago

You can use MatcherExtensions.Match to avoid creating mocking files.