DeferBenchmark.cs 753 B

123456789101112131415161718192021222324252627
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading;
  8. using BenchmarkDotNet.Attributes;
  9. namespace Benchmarks.System.Interactive
  10. {
  11. [MemoryDiagnoser]
  12. public class DeferBenchmark
  13. {
  14. [Params(1, 10, 100, 1000, 10000, 100000, 1000000)]
  15. public int N;
  16. private int _store;
  17. [Benchmark]
  18. public void Defer()
  19. {
  20. EnumerableEx.Defer(() => Enumerable.Range(1, N))
  21. .Subscribe(v => Volatile.Write(ref _store, v));
  22. }
  23. }
  24. }