Loading and processing each assembly in a seperate thread is faster. But only a bit faster. For example you will get much better milage by caching MethodInfos.
I would question the need for such an optimisation though.
results:
warm up single threaded Time Elapsed 465 ms
multi threaded Time Elapsed 173 ms
single threaded Time Elapsed 456 ms
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Reflection;
using System.Diagnostics;
namespace ConsoleApplication12 {
class Program {
static void TimeAction(string description, Action func) {
var watch = new Stopwatch();
watch.Start();
func();
watch.Stop();
Console.Write(description);
Console.WriteLine(" Time Elapsed {0} ms", watch.ElapsedMilliseconds);
}
static void Main(string[] args) {
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
// warm up
TimeAction("warm up single threaded", () =>
{
foreach (var assembly in assemblies) {
assembly.GetTypes().Select(type => type.GetMethods()).ToArray();
}
});
List<Thread> threads = new List<Thread>();
TimeAction("multi threaded", () => {
foreach (var assembly in assemblies) {
Thread t = new Thread(new ThreadStart( () =>
assembly.GetTypes().Select(type => type.GetMethods()).ToArray()
));
t.Start();
threads.Add(t);
}
foreach (var thread in threads) {
thread.Join();
}
});
TimeAction("single threaded", () =>
{
foreach (var assembly in assemblies) {
assembly.GetTypes().Select(type => type.GetMethods()).ToArray();
}
});
Console.ReadKey();
}
}
}