1
0

ToObservableBenchmark.cs 781 B

123456789101112131415161718192021222324252627282930
  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.Reactive.Linq;
  8. using System.Threading;
  9. using BenchmarkDotNet.Attributes;
  10. namespace Benchmarks.System.Reactive
  11. {
  12. [MemoryDiagnoser]
  13. public class ToObservableBenchmark
  14. {
  15. [Params(1, 10, 100, 1000, 10000, 100000, 1000000)]
  16. public int N;
  17. int _store;
  18. [Benchmark]
  19. public void Exact()
  20. {
  21. Enumerable.Range(1, N)
  22. .ToObservable()
  23. .Subscribe(v => Volatile.Write(ref _store, v));
  24. }
  25. }
  26. }