Three ways to compare lists of strings

While working, and re-working through the problem of tracking changes to AD group memberships (see HERE) the final “production” script that I wrote came out to over 300 lines and ended up being a little different to what I put in that previous post.  In practice some of the groups the script was tracking had more than 10,000 members – and the script was slow to run when comparing two lists, each with more than 10,000 entries.

So, I wrote this test, of 3 different methods to compare two lists of strings to track new and removed entries, and timed each one of them.

The sample data I used was two text files, each with near identical contents (random numbers between 10,000 and 10,000,000), with a couple of changes to each to mimic a small number of additions/removals.

Test 2 (below) was the first method I tried.  I came up with a left-of-center solution in Test 1 because Test 2 was achingly slow and I thought that there had to be a better way.

Test 3, well, the results of Test 3 speaks for itself.

 

The output of each of the tests (for $newnumbers and $removednumbers) are slightly different, but easily workable into any output you like.

I  repeated these tests over and over, and below is a fairly typical result:

 

Leave a Reply

Your email address will not be published. Required fields are marked *