private static void MoveNextBenchMut(BaseContainer <int> bcMut, int count, int mult) { // warmup for (int _ = 0; _ < 1; _++) { var cMut = new BlockCursor <int, object, BaseContainer <int> >(bcMut); for (int i = 0; i < count; i++) { cMut.MoveNext(); } } using (Benchmark.Run("Mut", count * mult)) { for (int _ = 0; _ < mult; _++) { var cMut = new BlockCursor <int, object, BaseContainer <int> >(bcMut); for (int i = 0; i < count; i++) { cMut.MoveNext(); } } } }
public BlockCursorView(BlockCursor model, EditorViewModel editorViewModel) { this._model = model; this._editorViewModel = editorViewModel; model.PropertyChanged += CursorChanged; editorViewModel.PropertyChanged += OffsetChanged; }
public void SetBlockCursorPosition(Vector2 location) { Vector2 lastPosition = BlockCursor.Position; BlockCursor.SetPosition(location); if (Mathf.Abs(Vector2.Distance(lastPosition, BlockCursor.Position)) > 0.0001) { RedrawNeeded = true; } }
// ReSharper disable once UnusedParameter.Local private static bool TryGetBlockAtSlow(long index, out DataBlock?block, out int blockIndex) { using (var bc = new BlockCursor <TKey, int, BaseContainer <TKey> >()) { if (bc.Move(index, false) == 0) { block = null; blockIndex = -1; return(false); } block = bc.CurrentBlock; blockIndex = bc.BlockIndex; return(true); } }
public void CouldMoveNext() { var count = 100; var len = count / 2; var bc = CreateIntBaseContainer(count, len); var c = new BlockCursor <int, object, BaseContainer <int> >(bc); for (int i = 0; i < len; i++) { Assert.IsTrue(c.MoveNext()); Assert.AreEqual(i, c._blockPosition); } Assert.AreEqual(1 - len, c.Move(long.MinValue, true)); bc.Dispose(); }
public void CouldMoveNextBench() { var count = 1000_000; var rounds = 20; var mult = 1_00; var bcImm = CreateIntBaseContainer(count, count); bcImm._flags = new Flags((byte)Mutability.ReadOnly | (byte)KeySorting.Strong); var bcMut = CreateIntBaseContainer(count, count); bcMut._flags = new Flags((byte)Mutability.Mutable | (byte)KeySorting.Strong); BlockCursor <int, object, BaseContainer <int> >[] useMut = new BlockCursor <int, object, BaseContainer <int> > [count]; var rng = new Random(42); var sm = new SortedMap <int, int>(count); var scm = new SortedChunkedMap <int, int>(); var sl = new SortedList <int, int>(count); for (int i = 0; i < count; i++) { var x = rng.NextDouble(); // if ((i & 1) == 0) // this is perfectly predicted on i7-8700, give ~300 MOPS if (x > 0.50) // this is not predicted at all, performance drops to ~130MOPS, but if we always use the Sync implementation the perf is the same ~300 MOPS, always NoSync ~360 MOPS { useMut[i] = new BlockCursor <int, object, BaseContainer <int> >(bcMut); } else { useMut[i] = new BlockCursor <int, object, BaseContainer <int> >(bcImm); } sm.Add(i, i); scm.Add(i, i); sl.Add(i, i); } var series = new Spreads.Collections.Experimental.Series <int, int>(Enumerable.Range(0, count).ToArray(), Enumerable.Range(0, count).ToArray()); for (int r = 0; r < rounds; r++) { //MoveNextBenchBranch(useMut, count, mult); //MoveNextBenchMut(bcMut, count, mult); //MoveNextBenchImm(bcImm, count, mult); //MoveNextBenchSL(sl, count, mult); MoveNextBenchSM(sm, count, mult); // MoveNextBenchSCM(scm, count, mult); MoveNextBenchSeries(series, count, mult); } Benchmark.Dump(); bcImm.Dispose(); bcMut.Dispose(); }
public SCursor(Series <TKey, TValue> source) { _cursor = new BlockCursor <TKey, TValue, Series <TKey, TValue> >(source); }