private static long ImHashMapGetIntKey <V>(ImHashMap <int, V> tree, int key, int times) { V ignored = default(V); var treeWatch = Stopwatch.StartNew(); for (int i = 0; i < times; i++) { ignored = tree.GetValueOrDefault(key); } treeWatch.Stop(); GC.KeepAlive(ignored); GC.Collect(); return(treeWatch.ElapsedMilliseconds); }
private static long TreeGet <T>(ImHashMap <Type, T> tree, Type key, int times) { T ignored = default(T); var treeWatch = Stopwatch.StartNew(); for (int i = 0; i < times; i++) { ignored = tree.GetValueOrDefault(key); } treeWatch.Stop(); GC.KeepAlive(ignored); GC.Collect(); return(treeWatch.ElapsedMilliseconds); }
public object Resolve(Type serviceType) { var cachedDelegate = _resolutionCache.Value.GetValueOrDefault(serviceType); if (cachedDelegate != null) { return(cachedDelegate.Invoke()); } var factory = _registrations.GetValueOrDefault(serviceType); if (factory == null) { return(null); } cachedDelegate = factory.CompileDelegate(); _resolutionCache.Swap(cache => cache.AddOrUpdate(serviceType, cachedDelegate)); return(cachedDelegate.Invoke()); }