internal void ResetBatch(BsonBuffer buffer, byte[] lastDocument) { buffer.Position = _firstDocumentStartPosition; buffer.Length = _firstDocumentStartPosition; buffer.WriteBytes(lastDocument); BackpatchMessageLength(buffer); }
// private methods private void AddOverflow(BsonBuffer buffer, byte[] serializedDocument) { buffer.WriteBytes(serializedDocument); _batchCount++; _batchLength = buffer.Position - _batchStartPosition; }
public void TestBenchmarks() { int iterations; DateTime start; DateTime end; TimeSpan duration; iterations = 1; start = DateTime.UtcNow; for (int i = 0; i < iterations; i++) { // about 2.06 on my machine //var doc = new BsonDocument { // { "a", 1 }, // { "b", 2.0 }, // { "c", "hello" }, // { "d", DateTime.UtcNow }, // { "e", true } // }; byte[] value = { 1, 2, 3, 4 }; MemoryStream stream = new MemoryStream(); for (int n = 0; n < 100000; n++) { stream.Write(value, 0, 4); } } end = DateTime.UtcNow; duration = end - start; System.Diagnostics.Debug.WriteLine(duration); start = DateTime.UtcNow; for (int i = 0; i < iterations; i++) { // about 2.22 on my machine //var doc = new BsonDocument { // { "a", BsonValue.Create((object) 1) }, // { "b", BsonValue.Create((object) 2.0) }, // { "c", BsonValue.Create((object) "hello") }, // { "d", BsonValue.Create((object) DateTime.UtcNow) }, // { "e", BsonValue.Create((object) true) } //}; byte[] value = { 1, 2, 3, 4 }; using (var buffer = new BsonBuffer()) { for (int n = 0; n < 100000; n++) { buffer.WriteBytes(value); } } } end = DateTime.UtcNow; duration = end - start; System.Diagnostics.Debug.WriteLine(duration); }