chargement et le traitement de chaque ensemble en un fil séparé est plus rapide. Mais seulement un peu plus vite. Par exemple, vous obtiendrez beaucoup mieux en mettant en cache MethodInfos.
Je doute cependant de la nécessité d'une telle optimisation.
résultats:
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();
}
}
}