Browse Source

Benchmark over lists and arrays

Dávid Karnok 7 years ago
parent
commit
ff7a9ead5e

+ 31 - 0
Ix.NET/Source/Benchmarks.System.Interactive/IgnoreElementsBenchmark.cs

@@ -18,6 +18,9 @@ namespace Benchmarks.System.Interactive
 
         private int _store;
 
+        private int[] _array;
+        private List<int> _list;
+
         [Benchmark]
         public void Ignore()
         {
@@ -25,5 +28,33 @@ namespace Benchmarks.System.Interactive
                 .IgnoreElements()
                 .Subscribe(v => Volatile.Write(ref _store, v));
         }
+
+        [Benchmark]
+        public void IgnoreList()
+        {
+            _list
+                .IgnoreElements()
+                .Subscribe(v => Volatile.Write(ref _store, v));
+        }
+
+        [Benchmark]
+        public void IgnoreArray()
+        {
+            _array
+                .IgnoreElements()
+                .Subscribe(v => Volatile.Write(ref _store, v));
+        }
+
+        [GlobalSetup]
+        public void Setup()
+        {
+            _array = new int[N];
+            _list = new List<int>(N);
+            for (var i = 0; i < N; i++)
+            {
+                _array[i] = i;
+                _list.Add(i);
+            }
+        }
     }
 }

+ 0 - 2
Ix.NET/Source/System.Interactive/IgnoreElements.cs

@@ -28,10 +28,8 @@ namespace System.Linq
         {
             using (var enumerator = source.GetEnumerator())
             {
-
                 while (enumerator.MoveNext()) ;
             }
-
             yield break;
         }
     }