RangeBenchmark.cs 682 B

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