private static void MeasurePerformance(string caption, IThreadLocalFactory threadLocalFactory) { for (int cycle = 0; cycle < TestCycles; cycle++) { Console.Out.Write("{0,-20} ... ", caption); Console.Out.Flush(); var threadDispatchQueue = threadLocalFactory.CreateThreadLocal( () => new Queue <Runnable>()); // Check access time - when not set long timeA = PerformanceObserver.MicroTime; for (int ii = 0; ii < TestIterations; ii++) { var value = threadDispatchQueue.Value; } // Check access time - with get or create long timeB = PerformanceObserver.MicroTime; for (int ii = 0; ii < TestIterations; ii++) { threadDispatchQueue.GetOrCreate(); } long timeC = PerformanceObserver.MicroTime; Console.WriteLine("{0} -> {1} us -> {2} us", timeA, timeB - timeA, timeC - timeB); } }
/// <summary> /// Initializes the <see cref="DefaultThreadLocalManager"/> class. /// </summary> public DefaultThreadLocalManager(IThreadLocalFactory threadLocalFactory) { DefaultThreadLocalFactory = threadLocalFactory; }
public BeanDependencyValidatorStrategy() { _stackFactory = new ThreadLocalFactory <Stack <ResolveStackEntry> >(new Func <Stack <ResolveStackEntry> >(() => new Stack <ResolveStackEntry>())); }