public void AsyncLocalPerfTest() { var values = Enumerable.Range(1, 50000).Select(n => new GenericParameterHelper(n)).ToArray(); var creates = Stopwatch.StartNew(); for (int i = 0; i < values.Length; i++) { this.asyncLocal = new Microsoft.VisualStudio.Threading.AsyncLocal <GenericParameterHelper>(); } creates.Stop(); var writes = Stopwatch.StartNew(); for (int i = 0; i < values.Length; i++) { this.asyncLocal.Value = values[0]; } writes.Stop(); var reads = Stopwatch.StartNew(); for (int i = 0; i < values.Length; i++) { var value = this.asyncLocal.Value; } reads.Stop(); // We don't actually validate the perf here. We just print out the results. this.Logger.WriteLine("Creating {0} instances took {1} ms", values.Length, creates.ElapsedMilliseconds); this.Logger.WriteLine("Saving {0} values took {1} ms", values.Length, writes.ElapsedMilliseconds); this.Logger.WriteLine("Reading {0} values took {1} ms", values.Length, reads.ElapsedMilliseconds); }
public AsyncLocalTests(ITestOutputHelper logger) : base(logger) { this.asyncLocal = new Microsoft.VisualStudio.Threading.AsyncLocal <GenericParameterHelper>(); }