RetryBenchmark.cs 911 B

12345678910111213141516171819202122232425262728293031323334
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT 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 RetryBenchmark
  13. {
  14. [Params(1, 10, 100, 1000, 10000, 100000, 1000000)]
  15. public int N;
  16. private int _store;
  17. [Benchmark]
  18. public void Finite()
  19. {
  20. Enumerable.Range(1, N).Retry(100)
  21. .Subscribe(v => Volatile.Write(ref _store, v));
  22. }
  23. [Benchmark]
  24. public void Infinite()
  25. {
  26. Enumerable.Range(1, N).Retry()
  27. .Subscribe(v => Volatile.Write(ref _store, v));
  28. }
  29. }
  30. }