BufferCountBenchmark.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 BufferCountBenchmark
  13. {
  14. [Params(1, 10, 100, 1000, 10000, 100000, 1000000)]
  15. public int N;
  16. private IList<int> _store;
  17. [Benchmark]
  18. public void Exact()
  19. {
  20. Enumerable.Range(1, N)
  21. .Buffer(1)
  22. .Subscribe(v => Volatile.Write(ref _store, v));
  23. }
  24. [Benchmark]
  25. public void Skip()
  26. {
  27. Enumerable.Range(1, N)
  28. .Buffer(1, 2)
  29. .Subscribe(v => Volatile.Write(ref _store, v));
  30. }
  31. [Benchmark]
  32. public void Overlap()
  33. {
  34. Enumerable.Range(1, N)
  35. .Buffer(2, 1)
  36. .Subscribe(v => Volatile.Write(ref _store, v));
  37. }
  38. }
  39. }