public void BenchmarkMostlyReadDictionary(int readsPerWrite) { Benchmark.Go("MostlyReadDictionary", iterations => { var methods = new MostlyReadDictionary <DataReaderMapper.MetaData, Delegate>(); while (iterations > 0) { var reader = CreateDataReader("extra" + iterations); var columns = DataReaderMapper.CreateColumnList(reader); GC.KeepAlive(methods.GetOrAdd(new DataReaderMapper.MetaData(typeof(Target), columns), Target.Create)); for (int i = 0; i < readsPerWrite; i++) { if (--iterations <= 0) { break; } GC.KeepAlive(methods.GetOrAdd(new DataReaderMapper.MetaData(typeof(Target), columns), Target.Create)); } } }); }
internal static Func <TIn, TOut, TOut> GetOrAdd <TIn, TOut>() { return((Func <TIn, TOut, TOut>)MapMethods.GetOrAdd(new TypePair(typeof(TIn), typeof(TOut)), _ => CreateMapDelegate(typeof(TIn), typeof(TOut)))); }