private void TestMongo3(int iterations) { List <WriteModel <BsonDocument> > list = new List <WriteModel <BsonDocument> >(7); Stopwatch sw = new Stopwatch(); for (int i = 0; i < iterations; i++) { string iStr = i.ToString(); Guid elementGuid = new Guid("00000000-0000-0000-0000-" + new string('0', 12 - iStr.Length) + iStr); list.Clear(); for (int j = 0; j < classifierTypes.Length; j++) { Classifier.Type type = classifierTypes[j]; Classifier c; if (type == Classifier.Type.CProps || type == Classifier.Type.CElements || type == Classifier.Type.CLinks) { c = new Classifier(type, i); } else { c = new Classifier(type, i, i, elementGuid); } BsonDocument mdbd = c.ToBsonDocument(); list.Add(new ReplaceOneModel <BsonDocument>(new BsonDocument("_id", c.Key), mdbd) { IsUpsert = true }); } sw.Start(); _classifier.BulkWrite(list); sw.Stop(); if (((i + 1) % 100) == 0) { Console.WriteLine(i + 1); } } sw.Stop(); Console.WriteLine($"TestMongo3. {iterations} итераций. {sw.Elapsed.ToString()}, {sw.ElapsedMilliseconds * 1000 / iterations} мc/1000"); }
private void TestMongo5(int count) { List <WriteModel <BsonDocument> > list = new List <WriteModel <BsonDocument> >(7); int incorrect1 = 0, incorrect2 = 0; Stopwatch sw1 = new Stopwatch(); Stopwatch sw2 = new Stopwatch(); for (int i = 0; i < count; i++) { list.Clear(); string iStr = i.ToString(); Guid elementGuid = new Guid("00000000-0000-0000-0000-" + new string('0', 12 - iStr.Length) + iStr); BsonDocument byIdxBd = null; for (int j = 0; j < classifierTypes.Length; j++) { Classifier.Type type = classifierTypes[j]; Classifier c; if (type == Classifier.Type.CProps || type == Classifier.Type.CElements || type == Classifier.Type.CLinks) { c = new Classifier(type, i); } else { c = new Classifier(type, i, i, elementGuid); } if (type == Classifier.Type.CProps) { byIdxBd = c.GetFindAllByClassifierIdBson(); } list.Add(new DeleteOneModel <BsonDocument>(c.GetFindByIdBson())); } if (i % 2 == 0) { sw1.Start(); BulkWriteResult bwr = _classifier.BulkWrite(list); sw1.Stop(); if (bwr.DeletedCount != 7) { incorrect1++; } } else { sw2.Start(); DeleteResult dr = _classifier.DeleteMany(byIdxBd); sw2.Stop(); if (dr.DeletedCount != 7) { incorrect2++; } } if (((i + 1) % 100) == 0) { Console.WriteLine(i + 1); } } Console.WriteLine($"TestMongo5. {count}/2. Id:{sw1.Elapsed.ToString()}, {sw1.ElapsedMilliseconds * 1000 / count} / 1000, {incorrect1}"); Console.WriteLine($"TestMongo5. {count}/2. Idx:{sw2.Elapsed.ToString()}, {sw2.ElapsedMilliseconds * 1000 / count} / 1000, {incorrect2}"); }
private void TestMongo4(int count) { int nulls1 = 0, nulls2 = 0; int incorrect1 = 0, incorrect2 = 0; Stopwatch sw1 = new Stopwatch(); Stopwatch sw2 = new Stopwatch(); for (int i = 0; i < count; i++) { string iStr = i.ToString(); Guid elementGuid = new Guid("00000000-0000-0000-0000-" + new string('0', 12 - iStr.Length) + iStr); for (int j = 0; j < classifierTypes.Length; j++) { Classifier.Type type = classifierTypes[j]; Classifier c; if (type == Classifier.Type.CProps || type == Classifier.Type.CElements || type == Classifier.Type.CLinks) { c = new Classifier(type, i); } else { c = new Classifier(type, i, i, elementGuid); } BsonDocument byIdBd = c.GetFindByIdBson(); BsonDocument byIdxBd = c.GetFindByClassifierIdBson(); sw1.Start(); BsonDocument bd1 = _classifier.Find(byIdBd).FirstOrDefault(); sw1.Stop(); if (bd1 == null) { nulls1++; } else { Classifier c1 = Classifier.FromBsonDocument(bd1); if (!c.Compare(c1)) { incorrect1++; } } sw2.Start(); BsonDocument bd2 = _classifier.Find(byIdxBd).FirstOrDefault(); sw2.Stop(); if (bd2 == null) { nulls2++; } else { Classifier c2 = Classifier.FromBsonDocument(bd2); if (!c.Compare(c2)) { incorrect2++; } } } if (((i + 1) % 100) == 0) { Console.WriteLine(i + 1); } } Console.WriteLine($"TestMongo4. Id:{sw1.Elapsed.ToString()}, {sw1.ElapsedMilliseconds * 1000 / count} / 1000, {nulls1}, {incorrect1}"); Console.WriteLine($"TestMongo4. Idx:{sw2.Elapsed.ToString()}, {sw2.ElapsedMilliseconds * 1000 / count} / 1000, {nulls2}, {incorrect2}"); }