public void run() { int i; Root root = (Root)db.Root; string tid = "Thread" + id + ":"; #if USE_GENERICS FieldIndex <string, Record> index = root.indices[id % nIndices]; #else FieldIndex index = root.indices[id % nIndices]; #endif for (i = 0; i < nRecords; i++) { db.BeginThreadTransaction(TransactionMode.Serializable); index.ExclusiveLock(); Record rec = new Record(); rec.key = tid + toStr(i); index.Put(rec); db.EndThreadTransaction(); } index.SharedLock(); i = 0; foreach (Record rec in index.StartsWith(tid)) { Debug.Assert(rec.key.Equals(tid + toStr(i))); i += 1; } Debug.Assert(i == nRecords); index.Unlock(); for (i = 0; i < nRecords; i++) { index.SharedLock(); string key = tid + toStr(i); Record rec = (Record)index[key]; Debug.Assert(rec.key.Equals(key)); index.Unlock(); } for (i = 0; i < nRecords; i++) { db.BeginThreadTransaction(TransactionMode.Serializable); index.ExclusiveLock(); Record rec = (Record)index.Remove(new Key(tid + toStr(i))); rec.Deallocate(); db.EndThreadTransaction(); } }
public void Update(RegisterInfo registerInfo, RegisterInfo newRegisterInfo) { Storage storage = DaoHelper.Instance.DbStorage; ClothRoot root = (ClothRoot)storage.Root; FieldIndex registerInfoOidIndex = root.RegisterInfoOidIndex; FieldIndex registerInfoNameIndex = root.RegisterInfoNameIndex; if (null == registerInfo || !registerInfoOidIndex.Contains(registerInfo)) { return; } storage.BeginThreadTransaction(TransactionMode.Exclusive); try { if (registerInfo.Name != newRegisterInfo.Name) { registerInfoNameIndex.Remove(registerInfo); registerInfo.Name = newRegisterInfo.Name; registerInfoNameIndex.Set(registerInfo); } registerInfo.SearchTime = newRegisterInfo.SearchTime; registerInfo.UpdateTime = newRegisterInfo.UpdateTime; registerInfo.LoginTime = newRegisterInfo.LoginTime; registerInfo.Md5Key = newRegisterInfo.Md5Key; registerInfo.Modify(); storage.EndThreadTransaction(); } catch (Exception) { // do some log storage.RollbackThreadTransaction(); } }
static public void Main(string[] args) { int i; if (args.Length < 1) { usage(); return; } int port = defaultPort; bool ack = false; bool async = false; String mapFile = null; String dbFile = null; String host = "localhost"; for (i = 1; i < args.Length; i++) { if (args[i] == "-async") { async = true; } else if (args[i] == "-ack") { ack = true; } else if (args[i] == "-map") { mapFile = args[++i]; } else if (args[i] == "-db") { dbFile = args[++i]; } else if (args[i] == "-port") { port = int.Parse(args[++i]); } else if (args[i] == "-host") { host = args[++i]; } else { usage(); } } if ("master" == args[0]) { ReplicationMasterStorage db = StorageFactory.Instance.CreateReplicationMasterStorage(host, port, new string[0], async ? asyncBufSize : 0, mapFile); db.SetProperty("perst.replication.ack", ack); db.Listener = new PerstListener(); if (dbFile == null) { db.Open(new NullFile(), 0); } else { db.Open(dbFile); } #if USE_GENERICS FieldIndex <int, Record> root = (FieldIndex <int, Record>)db.Root; if (root == null) { root = db.CreateFieldIndex <int, Record>("key", true); #else FieldIndex root = (FieldIndex)db.Root; if (root == null) { root = db.CreateFieldIndex(typeof(Record), "key", true); #endif db.Root = root; } DateTime start = DateTime.Now; for (i = 0; i < nIterations; i++) { if (i >= nRecords) { object obj = root.Remove(new Key(i - nRecords)); db.Deallocate(obj); } Record rec = new Record(); rec.key = i; root.Put(rec); if (i >= nRecords && i % transSize == 0) { db.Commit(); } } db.Close(); Console.WriteLine("Elapsed time for " + nIterations + " iterations: " + (DateTime.Now - start)); } else if ("slave" == args[0]) { ReplicationSlaveStorage db = StorageFactory.Instance.AddReplicationSlaveStorage(host, port, mapFile); db.SetProperty("perst.replication.ack", ack); db.Listener = new PerstListener(); while (true) { Console.WriteLine("Try to establish connection with master..."); if (dbFile == null) { db.Open(new NullFile(), 0); } else { db.Open(dbFile); } if (!db.IsConnected()) { db.Close(); Console.WriteLine("Failed to connect to master..."); Thread.Sleep(connectRetryTimeout); continue; } Console.WriteLine("Connection with master established"); DateTime total = new DateTime(0); int n = 0; while (true) { db.WaitForModification(); if (!db.IsConnected()) { Console.WriteLine("Connection with master is lost"); break; } db.BeginThreadTransaction(TransactionMode.ReplicationSlave); #if USE_GENERICS FieldIndex <int, Record> root = (FieldIndex <int, Record>)db.Root; #else FieldIndex root = (FieldIndex)db.Root; #endif if (root != null && root.Count == nRecords) { DateTime start = DateTime.Now; int prevKey = -1; i = 0; foreach (Record rec in root) { int key = rec.key; if (i == 0) { Console.WriteLine("First key: " + key); } Debug.Assert(prevKey < 0 || key == prevKey + 1); prevKey = key; i += 1; } Debug.Assert(i == nRecords); n += 1; total += (DateTime.Now - start); /* * if (n % 100 == 0) { * Console.WriteLine("Terminate slave..."); * Process.GetCurrentProcess().Kill(); * } */ } db.EndThreadTransaction(); } db.Close(); Console.WriteLine("Elapsed time for " + n + " iterations: " + total); } } else { usage(); } } }
static public void Main(string[] args) { int i; Storage db = StorageFactory.Instance.CreateStorage(); for (i = 0; i < args.Length; i++) { if ("altbtree" == args[i]) { db.SetProperty("perst.alternative.btree", true); } } db.Open("testcidx.dbs", pagePoolSize); #if USE_GENERICS MultiFieldIndex <Record> root = (MultiFieldIndex <Record>)db.Root; if (root == null) { root = db.CreateFieldIndex <Record>(new string[] { "intKey", "strKey" }, true); #else FieldIndex root = (FieldIndex)db.Root; if (root == null) { root = db.CreateFieldIndex(typeof(Record), new string[] { "intKey", "strKey" }, true); #endif db.Root = root; } DateTime start = DateTime.Now; long key = 1999; for (i = 0; i < nRecords; i++) { Record rec = new Record(); key = (3141592621L * key + 2718281829L) % 1000000007L; rec.intKey = (int)((ulong)key >> 32); rec.strKey = Convert.ToString((int)key); root.Put(rec); } db.Commit(); Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start)); start = DateTime.Now; key = 1999; int minKey = Int32.MaxValue; int maxKey = Int32.MinValue; for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; int intKey = (int)((ulong)key >> 32); String strKey = Convert.ToString((int)key); #if USE_GENERICS Record rec = root.Get(new Key(new Object[] { intKey, strKey })); #else Record rec = (Record)root.Get(new Key(new Object[] { intKey, strKey })); #endif Debug.Assert(rec != null && rec.intKey == intKey && rec.strKey.Equals(strKey)); if (intKey < minKey) { minKey = intKey; } if (intKey > maxKey) { maxKey = intKey; } } Console.WriteLine("Elapsed time for performing " + nRecords + " index searches: " + (DateTime.Now - start)); start = DateTime.Now; int n = 0; string prevStr = ""; int prevInt = minKey; foreach (Record rec in root.Range(new Key(minKey, ""), new Key(maxKey + 1, "???"), IterationOrder.AscentOrder)) { Debug.Assert(rec.intKey > prevInt || rec.intKey == prevInt && rec.strKey.CompareTo(prevStr) > 0); prevStr = rec.strKey; prevInt = rec.intKey; n += 1; } Debug.Assert(n == nRecords); n = 0; prevInt = maxKey + 1; foreach (Record rec in root.Range(new Key(minKey, "", false), new Key(maxKey + 1, "???", false), IterationOrder.DescentOrder)) { Debug.Assert(rec.intKey < prevInt || rec.intKey == prevInt && rec.strKey.CompareTo(prevStr) < 0); prevStr = rec.strKey; prevInt = rec.intKey; n += 1; } Debug.Assert(n == nRecords); Console.WriteLine("Elapsed time for iterating through " + (nRecords * 2) + " records: " + (DateTime.Now - start)); start = DateTime.Now; key = 1999; for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; int intKey = (int)((ulong)key >> 32); String strKey = Convert.ToString((int)key); #if USE_GENERICS Record rec = root.Get(new Key(new Object[] { intKey, strKey })); #else Record rec = (Record)root.Get(new Key(new Object[] { intKey, strKey })); #endif Debug.Assert(rec != null && rec.intKey == intKey && rec.strKey.Equals(strKey)); Debug.Assert(root.Contains(rec)); root.Remove(rec); rec.Deallocate(); } Debug.Assert(!root.GetEnumerator().MoveNext()); Debug.Assert(!root.Reverse().GetEnumerator().MoveNext()); Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start)); db.Close(); } }
static public void Main(string[] args) { int i; if (args.Length < 1) { usage(); return; } int port = defaultPort; bool ack = false; bool async = false; for (i = 1; i < args.Length; i++) { if (args[i].StartsWith("-")) { if (args[i] == "-async") { async = true; } else if (args[i] == "-ack") { ack = true; } else { usage(); } } else { port = int.Parse(args[i]); } } if ("master" == args[0]) { ReplicationMasterStorage db = StorageFactory.Instance.CreateReplicationMasterStorage(-1, new string[] { "localhost:" + port }, async ? asyncBufSize : 0); db.SetProperty("perst.file.noflush", true); db.SetProperty("perst.replication.ack", ack); db.Open("master.dbs", pagePoolSize); #if USE_GENERICS FieldIndex <int, Record> root = (FieldIndex <int, Record>)db.Root; if (root == null) { root = db.CreateFieldIndex <int, Record>("key", true); #else FieldIndex root = (FieldIndex)db.Root; if (root == null) { root = db.CreateFieldIndex(typeof(Record), "key", true); #endif db.Root = root; } DateTime start = DateTime.Now; for (i = 0; i < nIterations; i++) { if (i >= nRecords) { object obj = root.Remove(new Key(i - nRecords)); db.Deallocate(obj); } Record rec = new Record(); rec.key = i; root.Put(rec); if (i >= nRecords && i % transSize == 0) { db.Commit(); } } db.Close(); Console.WriteLine("Elapsed time for " + nIterations + " iterations: " + (DateTime.Now - start)); } else if ("slave" == args[0]) { ReplicationSlaveStorage db = StorageFactory.Instance.CreateReplicationSlaveStorage(port); db.SetProperty("perst.file.noflush", true); db.SetProperty("perst.replication.ack", ack); db.Open("slave.dbs", pagePoolSize); DateTime total = new DateTime(0); int n = 0; while (db.IsConnected()) { db.WaitForModification(); db.BeginThreadTransaction(TransactionMode.ReplicationSlave); #if USE_GENERICS FieldIndex <int, Record> root = (FieldIndex <int, Record>)db.Root; #else FieldIndex root = (FieldIndex)db.Root; #endif if (root != null && root.Count == nRecords) { DateTime start = DateTime.Now; int prevKey = -1; i = 0; foreach (Record rec in root) { int key = rec.key; Debug.Assert(prevKey < 0 || key == prevKey + 1); prevKey = key; i += 1; } Debug.Assert(i == nRecords); n += 1; total += (DateTime.Now - start); } db.EndThreadTransaction(); } db.Close(); Console.WriteLine("Elapsed time for " + n + " iterations: " + total); } else { usage(); } } }
static public void Main(string[] args) { int i; Storage db = StorageFactory.Instance.CreateStorage(); db.Open("testnullable.dbs", pagePoolSize); Root root = (Root)db.Root; if (root == null) { root = new Root(); #if USE_GENERICS root.pki = db.CreateFieldIndex <int, Record>("pk", true); root.ski = db.CreateFieldIndex <int?, Record>("sk", true); #else root.pki = db.CreateFieldIndex(typeof(Record), "pk", true); root.ski = db.CreateFieldIndex(typeof(Record), "sk", true); #endif db.Root = root; } #if USE_GENERICS FieldIndex <int, Record> pki = root.pki; FieldIndex <int?, Record> ski = root.ski; #else FieldIndex pki = root.pki; FieldIndex ski = root.ski; #endif DateTime start = DateTime.Now; for (i = 0; i < nRecords; i++) { Record rec = new Record(); rec.pk = i; if ((i & 1) != 0) { rec.sk = i; } pki.Put(rec); ski.Put(rec); } db.Commit(); System.Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start)); start = System.DateTime.Now; for (i = 0; i < nRecords; i++) { #if USE_GENERICS Record rec1 = pki[i]; Record rec2 = ski[i]; #else Record rec1 = (Record)pki[i]; Record rec2 = (Record)ski[i]; #endif Debug.Assert(rec1 != null); if ((i & 1) != 0) { Debug.Assert(rec2 == rec1); } else { Debug.Assert(rec2 == null); } } System.Console.WriteLine("Elapsed time for performing " + nRecords * 2 + " index searches: " + (DateTime.Now - start)); start = System.DateTime.Now; i = 0; foreach (Record rec in pki) { Debug.Assert(rec.pk == i); if ((i & 1) != 0) { Debug.Assert(rec.sk == i); } else { Debug.Assert(rec.sk == null); } i += 1; } Debug.Assert(i == nRecords); i = 1; foreach (Record rec in ski) { Debug.Assert(rec.pk == i && rec.sk == i); i += 2; } Debug.Assert(i == nRecords + 1); System.Console.WriteLine("Elapsed time for iteration through " + nRecords * 3 / 2 + " records: " + (DateTime.Now - start)); start = System.DateTime.Now; i = 1; foreach (Record rec in pki.Select("sk = pk")) { Debug.Assert(rec.pk == i && rec.sk == i); i += 2; } Debug.Assert(i == nRecords + 1); System.Console.WriteLine("Elapsed time for first sequential SubSQL search in " + nRecords + " records: " + (DateTime.Now - start)); i = 1; foreach (Record rec in pki.Select("sk+1 = pk+1 and (sk and 1) <> 0")) { Debug.Assert(rec.pk == i && rec.sk == i); i += 2; } Debug.Assert(i == nRecords + 1); System.Console.WriteLine("Elapsed time for second sequential SubSQL search in " + nRecords + " records: " + (DateTime.Now - start)); start = System.DateTime.Now; for (i = 0; i < nRecords; i++) { #if USE_GENERICS Record rec = pki[i]; #else Record rec = (Record)pki[i]; #endif bool removed = pki.Remove(rec); Debug.Assert(removed); removed = ski.Remove(rec); if ((i & 1) != 0) { Debug.Assert(removed); } else { Debug.Assert(!removed); } rec.Deallocate(); } System.Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start)); db.Close(); }
static public void Main(string[] args) { int i, j; Storage db = StorageFactory.Instance.CreateStorage(); db.SetProperty("perst.concurrent.iterator", true); db.Open("testrnd.dbs", pagePoolSize); #if USE_GENERICS FieldIndex <int, Record> root = (FieldIndex <int, Record>)db.Root; if (root == null) { root = db.CreateRandomAccessFieldIndex <int, Record>("i", true); db.Root = root; } #else FieldIndex root = (FieldIndex)db.Root; if (root == null) { root = db.CreateRandomAccessFieldIndex(typeof(Record), "i", true); db.Root = root; } #endif DateTime start = DateTime.Now; for (i = 0, j = 0; i < nRecords; i++, j += step) { Record rec = new Record(); rec.i = j % nRecords; root.Put(rec); } db.Commit(); Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start)); start = DateTime.Now; for (i = 0; i < nRecords; i++) { #if USE_GENERICS Record rec = root[i]; #else Record rec = (Record)root[i]; #endif Debug.Assert(rec.i == i); Debug.Assert(root.IndexOf(new Key(i)) == i); } Console.WriteLine("Elapsed time for performing " + nRecords + " Get operations: " + (DateTime.Now - start)); start = DateTime.Now; for (i = 0; i < nRecords; i++) { #if USE_GENERICS Record rec = root.GetAt(i); #else Record rec = (Record)root.GetAt(i); #endif Debug.Assert(rec.i == i); } Console.WriteLine("Elapsed time for performing " + nRecords + " GetAt operations: " + (DateTime.Now - start)); start = DateTime.Now; i = nRecords / 2; IDictionaryEnumerator e = root.GetDictionaryEnumerator(nRecords / 2, IterationOrder.AscentOrder); while (e.MoveNext()) { Debug.Assert((int)e.Key == i && ((Record)e.Value).i == i); i += 1; } Debug.Assert(i == nRecords); i = nRecords / 2 - 1; e = root.GetDictionaryEnumerator(nRecords / 2 - 1, IterationOrder.DescentOrder); while (e.MoveNext()) { Debug.Assert((int)e.Key == i && ((Record)e.Value).i == i); i -= 1; } Debug.Assert(i == -1); Console.WriteLine("Elapsed time for iteration through " + nRecords + " records: " + (DateTime.Now - start)); start = DateTime.Now; for (i = 0, j = 0; i < nRecords; i += step, j++) { #if USE_GENERICS Record rec = root.GetAt(i - j); #else Record rec = (Record)root.GetAt(i - j); #endif Debug.Assert(rec.i == i); root.Remove(rec); rec.Deallocate(); } Console.WriteLine("Elapsed time for deleting " + nRecords / step + " records: " + (DateTime.Now - start)); root.Clear(); Debug.Assert(!root.GetEnumerator().MoveNext()); db.Close(); }
public void Update(Cloth cloth, Cloth newCloth) { Storage storage = DaoHelper.Instance.DbStorage; ClothRoot root = (ClothRoot)storage.Root; FieldIndex clothOidIndex = root.ClothOidIndex; if (null == cloth || !clothOidIndex.Contains(cloth)) { return; } FieldIndex patternIndex = root.PatternIndex; BitIndex colorIndex = root.ColorIndex; BitIndex shapeIndex = root.ShapeIndex; FieldIndex pathIndex = root.PathIndex; FieldIndex colorNumIndex = root.ColorNumIndex; storage.BeginThreadTransaction(TransactionMode.Exclusive); try { // Pattern if (cloth.Pattern != null) { if (!cloth.Pattern.Equals(newCloth.Pattern)) { patternIndex.Remove(cloth); cloth.Pattern = newCloth.Pattern; patternIndex.Put(cloth); } } else if (newCloth.Pattern != null) { cloth.Pattern = newCloth.Pattern; patternIndex.Put(cloth); } // ColorNum if (cloth.ColorNum != newCloth.ColorNum) { colorNumIndex.Remove(cloth); cloth.ColorNum = newCloth.ColorNum; colorNumIndex.Put(cloth); } // Path if (cloth.Path != null) { if (!cloth.Path.Equals(newCloth.Path)) { pathIndex.Remove(cloth); cloth.Path = newCloth.Path; pathIndex.Set(cloth); } } else if (newCloth.Path != null) { cloth.Path = newCloth.Path; pathIndex.Set(cloth); } // Colors if (cloth.Colors != newCloth.Colors) { colorIndex.Remove(cloth); cloth.Colors = newCloth.Colors; colorIndex[cloth] = (int)cloth.Colors; } // Shapes if (cloth.Shapes != newCloth.Shapes) { shapeIndex.Remove(cloth); cloth.Shapes = newCloth.Shapes; shapeIndex[cloth] = (int)cloth.Shapes; } // Name if ((cloth.Name != null && !cloth.Name.Equals(newCloth.Name)) || (cloth.Name == null && newCloth.Name != null)) { cloth.Name = newCloth.Name; } // RGBSeparateColorVector if (newCloth.RGBSeparateColorVector != null && !newCloth.RGBSeparateColorVector.Equals(cloth.RGBSeparateColorVector)) { cloth.RGBSeparateColorVector = newCloth.RGBSeparateColorVector; } // RGBColorVector if (newCloth.RGBColorVector != null && !newCloth.RGBColorVector.Equals(cloth.RGBColorVector)) { cloth.RGBColorVector = newCloth.RGBColorVector; } // HSVColorVector if (newCloth.HSVColorVector != null && !newCloth.HSVColorVector.Equals(cloth.HSVColorVector)) { cloth.HSVColorVector = newCloth.HSVColorVector; } // HSVAynsColorVector if (newCloth.HSVAynsColorVector != null && !newCloth.HSVAynsColorVector.Equals(cloth.HSVAynsColorVector)) { cloth.HSVAynsColorVector = newCloth.HSVAynsColorVector; } // HLSColorVector if (newCloth.HLSColorVector != null && !newCloth.HLSColorVector.Equals(cloth.HLSColorVector)) { cloth.HLSColorVector = newCloth.HLSColorVector; } // DaubechiesWaveletVector if (newCloth.DaubechiesWaveletVector != null && !newCloth.DaubechiesWaveletVector.Equals(cloth.DaubechiesWaveletVector)) { cloth.DaubechiesWaveletVector = newCloth.DaubechiesWaveletVector; } // GaborVector if (newCloth.GaborVector != null && !newCloth.GaborVector.Equals(cloth.GaborVector)) { cloth.GaborVector = newCloth.GaborVector; } // CooccurrenceVector if (newCloth.CooccurrenceVector != null && !newCloth.CooccurrenceVector.Equals(cloth.CooccurrenceVector)) { cloth.CooccurrenceVector = newCloth.CooccurrenceVector; } cloth.UpdateTime = (0 == newCloth.UpdateTime.Ticks) ? DateTime.UtcNow : newCloth.UpdateTime; cloth.Modify(); storage.EndThreadTransaction(); } catch (Exception e) { // do some log storage.RollbackThreadTransaction(); } }
static public void Main(string[] args) { int i; Storage db = StorageFactory.Instance.CreateStorage(); bool serializableTransaction = false; bool compressed = false; bool encrypted = false; long pagePoolSize = 32 * 1024 * 1024; int nRecords = 100000; int hashPageSize = 101; int hashLoadFactor = 1; string password = "******"; for (i = 0; i < args.Length; i++) { switch (args[i]) { case "inmemory": pagePoolSize = 0; break; case "zip": compressed = true; break; case "crypt": encrypted = true; break; case "altbtree": db.SetProperty("perst.alternative.btree", true); break; case "serializable": db.SetProperty("perst.alternative.btree", true); serializableTransaction = true; break; case "pool": pagePoolSize = long.Parse(args[++i]); break; case "records": nRecords = int.Parse(args[++i]); break; case "page": hashPageSize = int.Parse(args[++i]); break; case "load": hashLoadFactor = int.Parse(args[++i]); break; default: Console.WriteLine("Unknown option: " + args[i]); return; } } if (pagePoolSize == 0) { db.Open(new NullFile(), 0); } else { #if !NET_FRAMEWORK_10 && (!COMPACT_NET_FRAMEWORK || COMPACT_NET_FRAMEWORK_35) if (compressed) { db.Open(new CompressedFile("testidx.dbs", encrypted ? password : null), pagePoolSize); } else #endif if (encrypted) { db.Open("testidx.dbs", pagePoolSize, password); } else { db.Open("testidx.dbs", pagePoolSize); } } if (serializableTransaction) { db.BeginThreadTransaction(TransactionMode.Serializable); } Root root = (Root)db.Root; if (root == null) { root = new Root(); #if USE_GENERICS root.tree = db.CreateFieldIndex <int, Record>("intKey", true); root.hash = db.CreateHash <int, Record>(hashPageSize, hashLoadFactor); #else root.tree = db.CreateFieldIndex(typeof(Record), "intKey", true); root.hash = db.CreateHash(hashPageSize, hashLoadFactor); #endif db.Root = root; } #if USE_GENERICS FieldIndex <int, Record> tree = root.tree; IPersistentMap <int, Record> hash = root.hash; #else FieldIndex tree = root.tree; IPersistentMap hash = root.hash; #endif DateTime start = DateTime.Now; for (i = 0; i < nRecords; i++) { Record rec = new Record(); rec.intKey = i * 2; tree.Put(rec); hash[rec.intKey] = rec; } if (serializableTransaction) { db.EndThreadTransaction(); } else { db.Commit(); } System.Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start)); start = System.DateTime.Now; for (i = 0; i < nRecords * 2; i++) { #if USE_GENERICS Record rec = tree[i]; #else Record rec = (Record)tree[i]; #endif if ((i & 1) != 0) { Debug.Assert(rec == null); } else { Debug.Assert(rec != null && rec.intKey == i); } } System.Console.WriteLine("Elapsed time for performing " + nRecords * 2 + " B-Tree searches: " + (DateTime.Now - start)); start = System.DateTime.Now; for (i = 0; i < nRecords * 2; i++) { #if USE_GENERICS Record rec = hash[i]; #else Record rec = (Record)hash[i]; #endif if ((i & 1) != 0) { Debug.Assert(rec == null); } else { Debug.Assert(rec != null && rec.intKey == i); } } System.Console.WriteLine("Elapsed time for performing " + nRecords * 2 + " hash searches: " + (DateTime.Now - start)); start = System.DateTime.Now; i = 0; foreach (Record rec in tree) { Debug.Assert(rec.intKey == i * 2); i += 1; } Debug.Assert(i == nRecords); System.Console.WriteLine("Elapsed time for iteration through " + nRecords + " records: " + (DateTime.Now - start)); start = System.DateTime.Now; if (serializableTransaction) { db.BeginThreadTransaction(TransactionMode.Serializable); } #if USE_GENERICS HashStatistic stat = ((PersistentHashImpl <int, Record>)hash).GetStatistic(); #else HashStatistic stat = ((PersistentHashImpl)hash).GetStatistic(); #endif for (i = 0; i < nRecords * 2; i++) { #if USE_GENERICS Record rec = hash[i]; #else Record rec = (Record)hash[i]; #endif if ((i & 1) != 0) { Debug.Assert(rec == null); } else { Debug.Assert(rec != null && rec.intKey == i); tree.Remove(rec); hash.Remove(rec.intKey); rec.Deallocate(); } } if (serializableTransaction) { db.EndThreadTransaction(); } Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start)); Console.WriteLine(stat); db.Close(); }