BufferCountBenchmark.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading;
  7. using BenchmarkDotNet.Attributes;
  8. namespace Benchmarks.System.Interactive
  9. {
  10. [MemoryDiagnoser]
  11. public class BufferCountBenchmark
  12. {
  13. [Params(1, 10, 100, 1000, 10000, 100000, 1000000)]
  14. public int N;
  15. private IList<int>? _store;
  16. [Benchmark]
  17. public void Exact()
  18. {
  19. Enumerable.Range(1, N)
  20. .Buffer(1)
  21. .Subscribe(v => Volatile.Write(ref _store, v));
  22. }
  23. [Benchmark]
  24. public void Skip()
  25. {
  26. Enumerable.Range(1, N)
  27. .Buffer(1, 2)
  28. .Subscribe(v => Volatile.Write(ref _store, v));
  29. }
  30. [Benchmark]
  31. public void Overlap()
  32. {
  33. Enumerable.Range(1, N)
  34. .Buffer(2, 1)
  35. .Subscribe(v => Volatile.Write(ref _store, v));
  36. }
  37. }
  38. }