static public void Main(string[] args) { const int pagePoolSize = 256*1024*1024; const int nRecords = 1024*1024; Storage db = StorageFactory.Instance.CreateStorage(); db.SetProperty("perst.concurrent.iterator", true); db.Open("testregex.dbs", pagePoolSize); #if USE_GENERICS RegexIndex<Record> index = (RegexIndex<Record>)db.Root; if (index == null) { index = db.CreateRegexIndex<Record>("key"); db.Root = index; } #else RegexIndex index = (RegexIndex)db.Root; if (index == null) { index = db.CreateRegexIndex(typeof(Record), "key"); db.Root = index; } #endif DateTime start = DateTime.Now; for (int i = 0; i < nRecords; i++) { Record rec = new Record(); rec.key = i.ToString("x"); index.Put(rec); } db.Commit(); Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start)); start = DateTime.Now; int n = 0; foreach (Record rec in index.Match("%Abcd%")) { n += 1; Debug.Assert(rec.key.IndexOf("abcd") >= 0); } Console.WriteLine("Elapsed time for query LIKE '%abcd%': " + (DateTime.Now - start)); Debug.Assert(n == 16*2); start = DateTime.Now; n = 0; foreach (Record rec in index.Match("1_2_3")) { n += 1; } Console.WriteLine("Elapsed time for query LIKE '1_2_3': " + (DateTime.Now - start)); Debug.Assert(n == 16*16); start = DateTime.Now; foreach (Record rec in index) { index.Remove(rec); rec.Deallocate(); } Debug.Assert(!index.GetEnumerator().MoveNext()); Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start)); db.Close(); }
public static void Main(string[] args) { Storage db = StorageFactory.Instance.CreateStorage(); db.Open("testmaxoid.dbs", pagePoolSize); int i; FieldIndex root = (FieldIndex) db.GetRoot(); if (root == null) { root = db.CreateFieldIndex(typeof(Record), "key", true); db.SetRoot(root); } long start = (DateTime.Now.Ticks - 621355968000000000) / 10000; for (i = 0; i < nRecords; i++) { Record rec = new Record(i); root.Put(rec); if (i % 1000000 == 0) { Console.Out.Write("Insert " + i + " records\r"); db.Commit(); } } db.Commit(); Console.Out.WriteLine("Elapsed time for inserting " + nRecords + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; for (i = 0; i < nRecords; i++) { Record rec = (Record) root.Get(new Key(i)); Assert.That(rec != null && rec.key == i); } Console.Out.WriteLine("Elapsed time for performing " + nRecords + " index searches: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; System.Collections.IEnumerator iterator = root.GetEnumerator(); for (i = 0; iterator.MoveNext(); i++) { Record rec = (Record) iterator.Current; Assert.That(rec.key == i); } Assert.That(i == nRecords); Console.Out.WriteLine("Elapsed time for iterating through " + nRecords + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; for (i = 0; i < nRecords; i++) { Record rec = (Record) root.Remove(new Key(i)); Assert.That(rec.key == i); rec.Deallocate(); } Console.Out.WriteLine("Elapsed time for deleting " + nRecords + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); db.Close(); }
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(); } }
static public void Main(string[] args) { const int pagePoolSize = 256 * 1024 * 1024; const int nRecords = 1024 * 1024; Storage db = StorageFactory.Instance.CreateStorage(); db.SetProperty("perst.concurrent.iterator", true); db.Open("testregex.dbs", pagePoolSize); #if USE_GENERICS RegexIndex <Record> index = (RegexIndex <Record>)db.Root; if (index == null) { index = db.CreateRegexIndex <Record>("key"); db.Root = index; } #else RegexIndex index = (RegexIndex)db.Root; if (index == null) { index = db.CreateRegexIndex(typeof(Record), "key"); db.Root = index; } #endif DateTime start = DateTime.Now; for (int i = 0; i < nRecords; i++) { Record rec = new Record(); rec.key = i.ToString("x"); index.Put(rec); } db.Commit(); Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start)); start = DateTime.Now; int n = 0; foreach (Record rec in index.Match("%Abcd%")) { n += 1; Debug.Assert(rec.key.IndexOf("abcd") >= 0); } Console.WriteLine("Elapsed time for query LIKE '%abcd%': " + (DateTime.Now - start)); Debug.Assert(n == 16 * 2); start = DateTime.Now; n = 0; foreach (Record rec in index.Match("1_2_3")) { n += 1; } Console.WriteLine("Elapsed time for query LIKE '1_2_3': " + (DateTime.Now - start)); Debug.Assert(n == 16 * 16); start = DateTime.Now; foreach (Record rec in index) { index.Remove(rec); rec.Deallocate(); } Debug.Assert(!index.GetEnumerator().MoveNext()); Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start)); db.Close(); }
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; Storage db = StorageFactory.Instance.CreateStorage(); db.Open("testlist2.dbs", pagePoolSize); #if USE_GENERICS IPersistentList<Record> root = (IPersistentList<Record>)db.Root; if (root == null) { root = db.CreateList<Record>(); db.Root = root; } #else IPersistentList root = (IPersistentList)db.Root; if (root == null) { root = db.CreateList(); db.Root = root; } #endif DateTime start = DateTime.Now; for (i = 0; i < nRecords/2; i++) { Record rec = new Record(); rec.i = i*2; root.Add(rec); } for (i = 1; i < nRecords; i+=2) { Record rec = new Record(); rec.i = i; root.Insert(i, 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); } Console.WriteLine("Elapsed time for performing " + nRecords + " gets: " + (DateTime.Now - start)); start = DateTime.Now; i = 0; foreach (Record rec in root) { Debug.Assert(rec.i == i); i += 1; } Debug.Assert(i == nRecords); Console.WriteLine("Elapsed time for iteration through " + nRecords + " records: " + (DateTime.Now - start)); start = DateTime.Now; for (i = 0; i < nRecords; i++) { #if USE_GENERICS Record rec = root[0]; #else Record rec = (Record)root[0]; #endif Debug.Assert(rec.i == i); root.RemoveAt(0); rec.Deallocate(); } Debug.Assert(!root.GetEnumerator().MoveNext()); Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start)); db.Close(); }
public static void Main(String[] args) { Storage db = StorageFactory.Instance.CreateStorage(); bool serializableTransaction = false; for (int i = 0; i < args.Length; i++) { if ("inmemory".Equals(args[i])) pagePoolSize = StorageConstants.INFINITE_PAGE_POOL; else if ("altbtree".Equals(args[i])) { db.SetProperty("perst.alternative.btree", true); //db.SetProperty("perst.object.cache.kind", "weak"); db.SetProperty("perst.object.cache.init.size", 1013); } else if ("serializable".Equals(args[i])) { db.SetProperty("perst.alternative.btree", true); serializableTransaction = true; } else Console.Error.WriteLine("Unrecognized option: " + args[i]); } db.Open("testidx.dbs", pagePoolSize); if (serializableTransaction) db.BeginThreadTransaction(StorageConstants.SERIALIZABLE_TRANSACTION); Indices root = (Indices) db.GetRoot(); if (root == null) { root = new Indices(); root.strIndex = db.CreateIndex(typeof(string), true); root.intIndex = db.CreateIndex(typeof(long), true); db.SetRoot(root); } Index intIndex = root.intIndex; Index strIndex = root.strIndex; long start = (DateTime.Now.Ticks - 621355968000000000) / 10000; long key = 1999; int i2; for (i2 = 0; i2 < nRecords; i2++) { Record rec = new Record(); key = (3141592621L * key + 2718281829L) % 1000000007L; rec.intKey = key; rec.strKey = Convert.ToString(key); intIndex.Put(new Key(rec.intKey), rec); strIndex.Put(new Key(rec.strKey), rec); /* if (i % 100000 == 0) { System.out.print("Insert " + i + " records\r"); db.Commit(); } */ } if (serializableTransaction) { db.EndThreadTransaction(); db.BeginThreadTransaction(StorageConstants.SERIALIZABLE_TRANSACTION); } else { db.Commit(); } //db.Gc(); Console.Out.WriteLine("Elapsed time for inserting " + nRecords + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; key = 1999; for (i2 = 0; i2 < nRecords; i2++) { key = (3141592621L * key + 2718281829L) % 1000000007L; Record rec1 = (Record) intIndex.Get(new Key(key)); Record rec2 = (Record) strIndex.Get(new Key(Convert.ToString(key))); Assert.That(rec1 != null && rec1 == rec2); } Console.Out.WriteLine("Elapsed time for performing " + nRecords * 2 + " index searches: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; key = System.Int64.MinValue; i2 = 0; foreach (Record rec in intIndex) { Assert.That(rec.intKey >= key); key = rec.intKey; ++i2; } Assert.That(i2 == nRecords); string strKey = ""; i2 = 0; foreach (Record rec in strIndex) { Assert.That(String.CompareOrdinal(rec.strKey, strKey) >= 0); strKey = rec.strKey; i2++; } Assert.That(i2 == nRecords); Console.Out.WriteLine("Elapsed time for iterating through " + (nRecords * 2) + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. Hashtable map = db.GetMemoryDump(); Console.Out.WriteLine("Memory usage"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; foreach (MemoryUsage usage in map.Values) { Console.Out.WriteLine(" " + usage.cls.FullName + ": instances=" + usage.nInstances + ", total size=" + usage.totalSize + ", allocated size=" + usage.allocatedSize); } Console.Out.WriteLine("Elapsed time for memory dump: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; key = 1999; for (i2 = 0; i2 < nRecords; i2++) { key = (3141592621L * key + 2718281829L) % 1000000007L; Record rec = (Record) intIndex.Get(new Key(key)); Record removed = (Record) intIndex.Remove(new Key(key)); Assert.That(removed == rec); //strIndex.Remove(new Key(Long.toString(key)), rec); strIndex.Remove(new Key(Convert.ToString(key))); rec.Deallocate(); } Assert.That(!intIndex.GetEnumerator().MoveNext()); Assert.That(!strIndex.GetEnumerator().MoveNext()); Assert.That(!intIndex.GetEnumerator(null, null, IndexSortOrder.Descent).MoveNext()); Assert.That(!strIndex.GetEnumerator(null, null, IndexSortOrder.Descent).MoveNext()); Assert.That(!intIndex.GetEnumerator(null, null, IndexSortOrder.Ascent).MoveNext()); Assert.That(!strIndex.GetEnumerator(null, null, IndexSortOrder.Ascent).MoveNext()); Console.Out.WriteLine("Elapsed time for deleting " + nRecords + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); db.Close(); }
static public void Main(string[] args) { int i; Storage db = StorageFactory.Instance.CreateStorage(); db.Open("testlist2.dbs", pagePoolSize); #if USE_GENERICS IPersistentList <Record> root = (IPersistentList <Record>)db.Root; if (root == null) { root = db.CreateList <Record>(); db.Root = root; } #else IPersistentList root = (IPersistentList)db.Root; if (root == null) { root = db.CreateList(); db.Root = root; } #endif DateTime start = DateTime.Now; for (i = 0; i < nRecords / 2; i++) { Record rec = new Record(); rec.i = i * 2; root.Add(rec); } for (i = 1; i < nRecords; i += 2) { Record rec = new Record(); rec.i = i; root.Insert(i, 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); } Console.WriteLine("Elapsed time for performing " + nRecords + " gets: " + (DateTime.Now - start)); start = DateTime.Now; i = 0; foreach (Record rec in root) { Debug.Assert(rec.i == i); i += 1; } Debug.Assert(i == nRecords); Console.WriteLine("Elapsed time for iteration through " + nRecords + " records: " + (DateTime.Now - start)); start = DateTime.Now; for (i = 0; i < nRecords; i++) { #if USE_GENERICS Record rec = root[0]; #else Record rec = (Record)root[0]; #endif Debug.Assert(rec.i == i); root.RemoveAt(0); rec.Deallocate(); } Debug.Assert(!root.GetEnumerator().MoveNext()); Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start)); db.Close(); }
public static void Main(string[] args) { Storage db = StorageFactory.Instance.CreateStorage(); for (int i = 0; i < args.Length; i++) { if ("altbtree".Equals(args[i])) { db.SetProperty("perst.alternative.btree", true); } } db.Open("testcidx.dbs", pagePoolSize); FieldIndex root = (FieldIndex) db.GetRoot(); if (root == null) { root = db.CreateFieldIndex(typeof(Record), new string[]{"intKey", "strKey"}, true); db.SetRoot(root); } long start = (DateTime.Now.Ticks - 621355968000000000) / 10000; long key = 1999; int i2; for (i2 = 0; i2 < nRecords; i2++) { Record rec = new Record(); key = (3141592621L * key + 2718281829L) % 1000000007L; rec.intKey = (int) (SupportClass.URShift(key, 32)); rec.strKey = Convert.ToString((int) key); root.Put(rec); } db.Commit(); Console.Out.WriteLine("Elapsed time for inserting " + nRecords + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; key = 1999; int minKey = System.Int32.MaxValue; int maxKey = System.Int32.MinValue; for (i2 = 0; i2 < nRecords; i2++) { key = (3141592621L * key + 2718281829L) % 1000000007L; int intKey = (int) (SupportClass.URShift(key, 32)); string strKey = Convert.ToString((int) key); Record rec = (Record) root.Get(new Key(new System.Object[]{(System.Int32) intKey, strKey})); Assert.That(rec != null && rec.intKey == intKey && rec.strKey.Equals(strKey)); if (intKey < minKey) { minKey = intKey; } if (intKey > maxKey) { maxKey = intKey; } } Console.Out.WriteLine("Elapsed time for performing " + nRecords + " index searches: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; System.Collections.IEnumerator iterator = root.GetEnumerator(new Key((System.Int32)minKey, ""), new Key((System.Int32)(maxKey + 1), "???"), IndexSortOrder.Ascent); int n = 0; string prevStr = ""; int prevInt = minKey; while (iterator.MoveNext()) { Record rec = (Record) iterator.Current; Assert.That(rec.intKey > prevInt || rec.intKey == prevInt && String.CompareOrdinal(rec.strKey, prevStr) > 0); prevStr = rec.strKey; prevInt = rec.intKey; n += 1; } Assert.That(n == nRecords); iterator = root.GetEnumerator(new Key((System.Int32)minKey, "", false), new Key((System.Int32)(maxKey + 1), "???", false), IndexSortOrder.Descent); n = 0; prevInt = maxKey + 1; while (iterator.MoveNext()) { Record rec = (Record) iterator.Current; Assert.That(rec.intKey < prevInt || rec.intKey == prevInt && String.CompareOrdinal(rec.strKey, prevStr) < 0); prevStr = rec.strKey; prevInt = rec.intKey; n += 1; } Assert.That(n == nRecords); Console.Out.WriteLine("Elapsed time for iterating through " + (nRecords * 2) + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; key = 1999; for (i2 = 0; i2 < nRecords; i2++) { key = (3141592621L * key + 2718281829L) % 1000000007L; int intKey = (int) (SupportClass.URShift(key, 32)); string strKey = Convert.ToString((int) key); Record rec = (Record) root.Get(new Key(new System.Object[]{(System.Int32) intKey, strKey})); Assert.That(rec != null && rec.intKey == intKey && rec.strKey.Equals(strKey)); Assert.That(root.Contains(rec)); root.Remove(rec); rec.Deallocate(); } Assert.That(!root.GetEnumerator().MoveNext()); Assert.That(!root.GetEnumerator(null, null, IndexSortOrder.Descent).MoveNext()); Assert.That(!root.GetEnumerator(null, null, IndexSortOrder.Ascent).MoveNext()); Console.Out.WriteLine("Elapsed time for deleting " + nRecords + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); db.Close(); }
static public void Main(string[] args) { int i; int nRecords = 100000; if (args.Length > 0) { nRecords = int.Parse(args[0]); } Storage db = StorageFactory.Instance.CreateStorage(); db.Open("testmap.dbs", pagePoolSize); Root root = (Root)db.Root; if (root == null) { root = new Root(); #if USE_GENERICS root.strMap = db.CreateMap <string, Record>(); root.intMap = db.CreateMap <long, Record>(); #else root.strMap = db.CreateMap(typeof(String)); root.intMap = db.CreateMap(typeof(long)); #endif db.Root = root; } #if USE_GENERICS IDictionary <string, Record> strMap = root.strMap; IDictionary <long, Record> intMap = root.intMap; #else IDictionary intMap = root.intMap; IDictionary strMap = root.strMap; #endif DateTime start = DateTime.Now; long key = 1999; for (i = 0; i < nRecords; i++) { Record rec = new Record(); key = (3141592621L * key + 2718281829L) % 1000000007L; rec.intKey = key; rec.strKey = System.Convert.ToString(key); intMap[rec.intKey] = rec; strMap[rec.strKey] = rec; Debug.Assert(intMap[rec.intKey] == rec); Debug.Assert(strMap[rec.strKey] == rec); } db.Commit(); System.Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start)); start = System.DateTime.Now; key = 1999; for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; #if USE_GENERICS Record rec1 = intMap[key]; Record rec2 = strMap[Convert.ToString(key)]; #else Record rec1 = (Record)intMap[key]; Record rec2 = (Record)strMap[Convert.ToString(key)]; #endif Debug.Assert(rec1 != null && rec1 == rec2); } System.Console.WriteLine("Elapsed time for performing " + nRecords * 2 + " map searches: " + (DateTime.Now - start)); start = System.DateTime.Now; key = Int64.MinValue; i = 0; foreach (Record rec in intMap.Values) { Debug.Assert(rec.intKey >= key); key = rec.intKey; i += 1; } Debug.Assert(i == nRecords); key = Int64.MinValue; i = 0; foreach (long k in intMap.Keys) { Debug.Assert(k >= key); key = k; i += 1; } Debug.Assert(i == nRecords); i = 0; String strKey = ""; foreach (Record rec in strMap.Values) { Debug.Assert(rec.strKey.CompareTo(strKey) >= 0); strKey = rec.strKey; i += 1; } Debug.Assert(i == nRecords); i = 0; strKey = ""; foreach (String s in strMap.Keys) { Debug.Assert(s.CompareTo(strKey) >= 0); strKey = s; i += 1; } Debug.Assert(i == nRecords); System.Console.WriteLine("Elapsed time for 4 iteration through " + nRecords + " records: " + (DateTime.Now - start)); start = System.DateTime.Now; key = 1999; for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; #if USE_GENERICS Record rec = intMap[key]; Debug.Assert(intMap.Remove(key)); Debug.Assert(strMap.Remove(Convert.ToString(key))); #else Record rec = (Record)intMap[key]; intMap.Remove(key); strMap.Remove(Convert.ToString(key)); #endif rec.Deallocate(); } System.Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start)); db.Close(); }
public void Run(TestConfig config) { int i; int count = config.Count; var res = new TestIndex2Result(); config.Result = res; var start = DateTime.Now; IDatabase db = config.GetDatabase(); Root root = (Root)db.Root; Tests.Assert(root == null); root = new Root(); root.strIndex = db.CreateSortedCollection <string, Record>(new StrRecordComparator(), IndexType.Unique); root.intIndex = db.CreateSortedCollection <long, Record>(new IntRecordComparator(), IndexType.Unique); db.Root = root; ISortedCollection <long, Record> intIndex = root.intIndex; ISortedCollection <string, Record> strIndex = root.strIndex; foreach (var key in Tests.KeySeq(count)) { Record rec = new Record(); rec.intKey = key; rec.strKey = System.Convert.ToString(key); intIndex.Add(rec); strIndex.Add(rec); } db.Commit(); res.InsertTime = DateTime.Now - start; start = System.DateTime.Now; foreach (var key in Tests.KeySeq(count)) { Record rec1 = intIndex[key]; Record rec2 = strIndex[Convert.ToString(key)]; } res.IndexSearch = DateTime.Now - start; start = System.DateTime.Now; var k = Int64.MinValue; i = 0; foreach (Record rec in intIndex) { Tests.Assert(rec.intKey >= k); k = rec.intKey; i += 1; } Tests.Assert(i == count); i = 0; String strKey = ""; foreach (Record rec in strIndex) { Tests.Assert(rec.strKey.CompareTo(strKey) >= 0); strKey = rec.strKey; i += 1; } Tests.Assert(i == count); res.IterationTime = DateTime.Now - start; start = DateTime.Now; res.MemoryUsage = db.GetMemoryUsage().Values; start = System.DateTime.Now; foreach (var key in Tests.KeySeq(count)) { Record rec = intIndex[key]; intIndex.Remove(rec); strIndex.Remove(rec); rec.Deallocate(); } res.RemoveTime = DateTime.Now - start; db.Close(); //Tests.DumpMemoryUsage(res.TypeMemoryUsage); }
public static void Main(string[] args) { Storage db = StorageFactory.Instance.CreateStorage(); db.Open("testidx2.dbs", pagePoolSize); Indices root = (Indices) db.GetRoot(); if (root == null) { root = new Indices(); root.strIndex = db.CreateSortedCollection(new StrRecordComparator(), true); root.intIndex = db.CreateSortedCollection(new IntRecordComparator(), true); db.SetRoot(root); } SortedCollection intIndex = root.intIndex; SortedCollection strIndex = root.strIndex; long start = (System.DateTime.Now.Ticks - 621355968000000000) / 10000; long key = 1999; int i; for (i = 0; i < nRecords; i++) { Record rec = new Record(); key = (3141592621L * key + 2718281829L) % 1000000007L; rec.intKey = key; rec.strKey = System.Convert.ToString(key); intIndex.Add(rec); strIndex.Add(rec); } db.Commit(); db.Gc(); Console.Out.WriteLine("Elapsed time for inserting " + nRecords + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; key = 1999; for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; Record rec1 = (Record) intIndex.Get((long) key); Record rec2 = (Record) strIndex.Get(Convert.ToString(key)); Assert.That(rec1 != null && rec1 == rec2); } Console.Out.WriteLine("Elapsed time for performing " + nRecords * 2 + " index searches: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; System.Collections.IEnumerator iterator = intIndex.GetEnumerator(); key = Int64.MinValue; for (i = 0; iterator.MoveNext(); i++) { Record rec = (Record) iterator.Current; Assert.That(rec.intKey >= key); key = rec.intKey; } Assert.That(i == nRecords); iterator = strIndex.GetEnumerator(); string strKey = ""; for (i = 0; iterator.MoveNext(); i++) { Record rec = (Record) iterator.Current; Assert.That(String.CompareOrdinal(rec.strKey, strKey) >= 0); strKey = rec.strKey; } Assert.That(i == nRecords); Console.Out.WriteLine("Elapsed time for iterating through " + (nRecords * 2) + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); System.Collections.Hashtable map = db.GetMemoryDump(); iterator = map.Values.GetEnumerator(); Console.Out.WriteLine("Memory usage"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; while (iterator.MoveNext()) { MemoryUsage usage = (MemoryUsage) iterator.Current; System.Console.Out.WriteLine(" " + usage.cls.FullName + ": instances=" + usage.nInstances + ", total size=" + usage.totalSize + ", allocated size=" + usage.allocatedSize); } System.Console.Out.WriteLine("Elapsed time for memory dump: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; key = 1999; for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; Record rec = (Record) intIndex.Get((long) key); intIndex.Remove(rec); strIndex.Remove(rec); rec.Deallocate(); } Assert.That(!intIndex.GetEnumerator().MoveNext()); Assert.That(!strIndex.GetEnumerator().MoveNext()); Assert.That(!intIndex.GetEnumerator(null, null).MoveNext()); Assert.That(!strIndex.GetEnumerator(null, null).MoveNext()); Console.Out.WriteLine("Elapsed time for deleting " + nRecords + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); db.Close(); }
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(); } }
public static void Main(string[] args) { Storage db = StorageFactory.Instance.CreateStorage(); db.Open("testmod.dbs", pagePoolSize); Indices root = (Indices) db.GetRoot(); if (root == null) { root = new Indices(); root.strIndex = db.CreateIndex(typeof(string), true); root.intIndex = db.CreateIndex(typeof(long), true); db.SetRoot(root); } Index intIndex = root.intIndex; Index strIndex = root.strIndex; long start = (DateTime.Now.Ticks - 621355968000000000) / 10000; long key = 1999; int i; for (i = 0; i < nRecords; i++) { Record rec = new Record(); key = (3141592621L * key + 2718281829L) % 1000000007L; rec.intKey = key; rec.strKey = Convert.ToString(key); intIndex.Put(new Key(rec.intKey), rec); strIndex.Put(new Key(rec.strKey), rec); } db.Commit(); Console.Out.WriteLine("Elapsed time for inserting " + nRecords + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; for (int j = 0; j < nIterations; j++) { key = 1999; for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; Record rec = (Record) intIndex.Get(new Key(key)); rec.strKey = reverseString(rec.strKey); if ((i & 255) == 0) { rec.Store(); } else { rec.Modify(); } } Console.Out.WriteLine("Iteration " + j); db.Commit(); } Console.Out.WriteLine("Elapsed time for performing " + nRecords * nIterations + " updates: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; key = 1999; for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; Record rec1 = (Record) intIndex.Get(new Key(key)); Record rec2 = (Record) strIndex.Get(new Key(Convert.ToString(key))); Assert.That(rec1 != null && rec1 == rec2); } Console.Out.WriteLine("Elapsed time for performing " + nRecords * 2 + " index searches: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); start = (DateTime.Now.Ticks - 621355968000000000) / 10000; key = 1999; for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; Record rec = (Record) intIndex.Get(new Key(key)); intIndex.Remove(new Key(key)); strIndex.Remove(new Key(Convert.ToString(key)), rec); rec.Deallocate(); } Console.Out.WriteLine("Elapsed time for deleting " + nRecords + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds"); db.Close(); }
static public void Main(string[] args) { int i; Storage db = StorageFactory.Instance.CreateStorage(); bool serializableTransaction = false; bool compressed = false; bool encrypted = false; bool multifile = false; long pagePoolSize = 32 * 1024 * 1024; int nRecords = 100000; string password = "******"; bool populate = false; 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 "multifile": multifile = 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 "populate": populate = true; break; default: Console.WriteLine("Unknown option: " + args[i]); return; } } string dbName = multifile ? "@testidx.mfd" : "testidx.dbs"; #if !NET_FRAMEWORK_10 && (!COMPACT_NET_FRAMEWORK || COMPACT_NET_FRAMEWORK_35) if (compressed) { db.Open(new CompressedFile(dbName, encrypted ? password : null), pagePoolSize); } else #endif if (encrypted) { db.Open(dbName, pagePoolSize, password); } else { db.Open(dbName, pagePoolSize); } if (serializableTransaction) { db.BeginThreadTransaction(TransactionMode.Serializable); } Root root = (Root)db.Root; if (root == null) { root = new Root(); #if USE_GENERICS root.strIndex = db.CreateIndex <string, Record>(true); root.intIndex = db.CreateIndex <long, Record>(true); #else root.strIndex = db.CreateIndex(typeof(String), true); root.intIndex = db.CreateIndex(typeof(long), true); #endif db.Root = root; } #if USE_GENERICS Index <string, Record> strIndex = root.strIndex; Index <long, Record> intIndex = root.intIndex; #else Index intIndex = root.intIndex; Index strIndex = root.strIndex; #endif DateTime start = DateTime.Now; long key = 1999; for (i = 0; i < nRecords; i++) { Record rec = new Record(); key = (3141592621L * key + 2718281829L) % 1000000007L; rec.intKey = key; rec.strKey = System.Convert.ToString(key); intIndex[rec.intKey] = rec; strIndex[rec.strKey] = rec; if (i % 100000 == 0) { Console.Write("Iteration " + i + "\r"); } } if (serializableTransaction) { db.EndThreadTransaction(); } else { db.Commit(); } System.Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start)); start = System.DateTime.Now; key = 1999; for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; #if USE_GENERICS Record rec1 = intIndex[key]; Record rec2 = strIndex[Convert.ToString(key)]; #else Record rec1 = (Record)intIndex[key]; Record rec2 = (Record)strIndex[Convert.ToString(key)]; #endif Debug.Assert(rec1 != null && rec1 == rec2); } System.Console.WriteLine("Elapsed time for performing " + nRecords * 2 + " index searches: " + (DateTime.Now - start)); start = System.DateTime.Now; key = Int64.MinValue; i = 0; foreach (Record rec in intIndex) { Debug.Assert(rec.intKey >= key); key = rec.intKey; i += 1; } Debug.Assert(i == nRecords); i = 0; String strKey = ""; foreach (Record rec in strIndex) { Debug.Assert(rec.strKey.CompareTo(strKey) >= 0); strKey = rec.strKey; i += 1; } Debug.Assert(i == nRecords); System.Console.WriteLine("Elapsed time for iteration through " + (nRecords * 2) + " records: " + (DateTime.Now - start)); Hashtable map = db.GetMemoryDump(); Console.WriteLine("Memory usage"); start = DateTime.Now; foreach (MemoryUsage usage in map.Values) { Console.WriteLine(" " + usage.type.Name + ": instances=" + usage.nInstances + ", total size=" + usage.totalSize + ", allocated size=" + usage.allocatedSize); } Console.WriteLine("Elapsed time for memory dump: " + (DateTime.Now - start)); if (!populate) { start = System.DateTime.Now; key = 1999; if (serializableTransaction) { db.BeginThreadTransaction(TransactionMode.Serializable); } for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; #if USE_GENERICS Record rec = intIndex.Get(key); Record removed = intIndex.RemoveKey(key); #else Record rec = (Record)intIndex[key]; Record removed = (Record)intIndex.RemoveKey(key); #endif Debug.Assert(removed == rec); strIndex.Remove(new Key(System.Convert.ToString(key)), rec); rec.Deallocate(); } if (serializableTransaction) { db.EndThreadTransaction(); } System.Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start)); } db.Close(); }
static public void Main(string[] args) { int i; Storage db = StorageFactory.Instance.CreateStorage(); db.Open("testjsql.dbs", pagePoolSize); Root root = (Root)db.Root; if (root == null) { root = new Root(); #if USE_GENERICS root.strIndex = db.CreateFieldIndex <string, Record>("strKey", true); root.intIndex = db.CreateFieldIndex <long, Record>("intKey", true); root.dateIndex = db.CreateFieldIndex <DateTime, Record>("dateKey", false); #else root.strIndex = db.CreateFieldIndex(typeof(Record), "strKey", true); root.intIndex = db.CreateFieldIndex(typeof(Record), "intKey", true); root.dateIndex = db.CreateFieldIndex(typeof(Record), "dateKey", false); #endif db.Root = root; } #if USE_GENERICS FieldIndex <string, Record> strIndex = root.strIndex; FieldIndex <long, Record> intIndex = root.intIndex; FieldIndex <DateTime, Record> dateIndex = root.dateIndex; IEnumerator <Record> enumerator; #else FieldIndex intIndex = root.intIndex; FieldIndex strIndex = root.strIndex; FieldIndex dateIndex = root.dateIndex; IEnumerator enumerator; #endif DateTime start = DateTime.Now; DateTime begin = start; long key = 1999; for (i = 0; i < nRecords; i++) { Record rec = new Record(); key = (3141592621L * key + 2718281829L) % 1000000007L; rec.intKey = key; rec.strKey = System.Convert.ToString(key); rec.dateKey = DateTime.Now; intIndex[rec.intKey] = rec; strIndex[rec.strKey] = rec; dateIndex[rec.dateKey] = rec; } db.Commit(); DateTime end = DateTime.Now; System.Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (end - start)); start = System.DateTime.Now; key = 1999; #if USE_GENERICS Query <Record> q1 = db.CreateQuery <Record>(); q1.Prepare("strKey=?"); Query <Record> q2 = db.CreateQuery <Record>(); q2.Prepare("intKey=?"); Query <Record> q3 = db.CreateQuery <Record>(); q3.Prepare("dateKey between ? and ?"); #else Query q1 = db.CreateQuery(); q1.Prepare(typeof(Record), "strKey=?"); Query q2 = db.CreateQuery(); q2.Prepare(typeof(Record), "intKey=?"); Query q3 = db.CreateQuery(); q3.Prepare(typeof(Record), "dateKey between ? and ?"); #endif q1.AddIndex("strKey", strIndex); q2.AddIndex("intKey", intIndex); q3.AddIndex("dateKey", dateIndex); for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; q1[1] = Convert.ToString(key); enumerator = q1.Execute(intIndex).GetEnumerator(); enumerator.MoveNext(); #if USE_GENERICS Record rec1 = enumerator.Current; #else Record rec1 = (Record)enumerator.Current; #endif Debug.Assert(!enumerator.MoveNext()); q2[1] = key; enumerator = q2.Execute(strIndex).GetEnumerator(); enumerator.MoveNext(); #if USE_GENERICS Record rec2 = enumerator.Current; #else Record rec2 = (Record)enumerator.Current; #endif Debug.Assert(rec1 != null && rec1 == rec2); } System.Console.WriteLine("Elapsed time for performing " + nRecords * 2 + " index searches: " + (DateTime.Now - start)); start = System.DateTime.Now; key = Int64.MinValue; i = 0; foreach (Record rec in intIndex.Select("strKey=string(intKey)")) { Debug.Assert(rec.intKey >= key); key = rec.intKey; i += 1; } Debug.Assert(i == nRecords); System.Console.WriteLine("Elapsed time for iteration through " + nRecords + " records: " + (DateTime.Now - start)); start = System.DateTime.Now; key = Int64.MinValue; i = 0; foreach (Record rec in strIndex.Select("(intKey and 1023) = 0 order by intKey")) { Debug.Assert(rec.intKey >= key); key = rec.intKey; i += 1; } System.Console.WriteLine("Elapsed time for ordering " + i + " records: " + (DateTime.Now - start)); start = System.DateTime.Now; DateTime curr = begin; i = 0; q3[1] = begin; q3[2] = end; foreach (Record rec in q3.Execute(dateIndex)) { Debug.Assert(rec.dateKey >= curr); curr = rec.dateKey; i += 1; } Debug.Assert(i == nRecords); System.Console.WriteLine("Elapsed time for iteration through date index for " + nRecords + " records: " + (DateTime.Now - start)); start = System.DateTime.Now; key = 1999; foreach (Record rec in intIndex) { rec.Deallocate(); } intIndex.Deallocate(); strIndex.Deallocate(); dateIndex.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(); }
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(); }
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, 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(); }
static public void Main(string[] args) { int i; Storage db = StorageFactory.Instance.CreateStorage(); bool serializableTransaction = false; for (i = 0; i < args.Length; i++) { if ("inmemory" == args[i]) { pagePoolSize = Storage.INFINITE_PAGE_POOL; } else if ("altbtree" == args[i]) { db.SetProperty("perst.alternative.btree", true); } else if ("serializable" == args[i]) { db.SetProperty("perst.alternative.btree", true); serializableTransaction = true; } else { Console.WriteLine("Unrecognized option: " + args[i]); } } db.Open("testidx.dbs", pagePoolSize); if (serializableTransaction) { db.BeginThreadTransaction(TransactionMode.Serializable); } Root root = (Root)db.Root; if (root == null) { root = new Root(); root.strIndex = db.CreateIndex(typeof(String), true); root.intIndex = db.CreateIndex(typeof(long), true); db.Root = root; } Index intIndex = root.intIndex; Index strIndex = root.strIndex; DateTime start = DateTime.Now; long key = 1999; for (i = 0; i < nRecords; i++) { Record rec = new Record(); key = (3141592621L * key + 2718281829L) % 1000000007L; rec.intKey = key; rec.strKey = System.Convert.ToString(key); intIndex.Put(new Key(rec.intKey), rec); strIndex.Put(new Key(rec.strKey), rec); if (i % 100000 == 0) { db.Commit(); Console.Write("Iteration " + i + "\r"); } } if (serializableTransaction) { db.EndThreadTransaction(); db.BeginThreadTransaction(TransactionMode.Serializable); } else { db.Commit(); } System.Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start)); start = System.DateTime.Now; key = 1999; for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; Record rec1 = (Record)intIndex.Get(new Key(key)); Record rec2 = (Record)strIndex.Get(new Key(Convert.ToString(key))); Debug.Assert(rec1 != null && rec1 == rec2); } System.Console.WriteLine("Elapsed time for performing " + nRecords * 2 + " index searches: " + (DateTime.Now - start)); start = System.DateTime.Now; key = Int64.MinValue; i = 0; foreach (Record rec in intIndex) { Debug.Assert(rec.intKey >= key); key = rec.intKey; i += 1; } Debug.Assert(i == nRecords); i = 0; String strKey = ""; foreach (Record rec in strIndex) { Debug.Assert(rec.strKey.CompareTo(strKey) >= 0); strKey = rec.strKey; i += 1; } Debug.Assert(i == nRecords); System.Console.WriteLine("Elapsed time for iteration through " + (nRecords * 2) + " records: " + (DateTime.Now - start)); Hashtable map = db.GetMemoryDump(); Console.WriteLine("Memory usage"); start = DateTime.Now; foreach (MemoryUsage usage in db.GetMemoryDump().Values) { Console.WriteLine(" " + usage.type.Name + ": instances=" + usage.nInstances + ", total size=" + usage.totalSize + ", allocated size=" + usage.allocatedSize); } Console.WriteLine("Elapsed time for memory dump: " + (DateTime.Now - start)); start = System.DateTime.Now; key = 1999; for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; Record rec = (Record)intIndex.Get(new Key(key)); Record removed = (Record)intIndex.Remove(new Key(key)); Debug.Assert(removed == rec); strIndex.Remove(new Key(System.Convert.ToString(key)), rec); rec.Deallocate(); } System.Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start)); db.Close(); }
internal static int pagePoolSize = 0; // infine page pool static public void Main(System.String[] args) { int i; Storage db = StorageFactory.Instance.CreateStorage(); db.Open("testidx2.dbs", pagePoolSize); Root root = (Root)db.Root; if (root == null) { root = new Root(); #if USE_GENERICS root.strIndex = db.CreateSortedCollection <string, Record>(new StrRecordComparator(), true); root.intIndex = db.CreateSortedCollection <long, Record>(new IntRecordComparator(), true); #else root.strIndex = db.CreateSortedCollection(new StrRecordComparator(), true); root.intIndex = db.CreateSortedCollection(new IntRecordComparator(), true); #endif db.Root = root; } #if USE_GENERICS SortedCollection <long, Record> intIndex = root.intIndex; SortedCollection <string, Record> strIndex = root.strIndex; #else SortedCollection intIndex = root.intIndex; SortedCollection strIndex = root.strIndex; #endif DateTime start = DateTime.Now; long key = 1999; for (i = 0; i < nRecords; i++) { Record rec = new Record(); key = (3141592621L * key + 2718281829L) % 1000000007L; rec.intKey = key; rec.strKey = System.Convert.ToString(key); intIndex.Add(rec); strIndex.Add(rec); } db.Commit(); System.Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start)); start = System.DateTime.Now; key = 1999; for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; #if USE_GENERICS Record rec1 = intIndex[key]; Record rec2 = strIndex[Convert.ToString(key)]; #else Record rec1 = (Record)intIndex[key]; Record rec2 = (Record)strIndex[Convert.ToString(key)]; #endif Debug.Assert(rec1 != null && rec1 == rec2); } System.Console.WriteLine("Elapsed time for performing " + nRecords * 2 + " index searches: " + (DateTime.Now - start)); start = System.DateTime.Now; key = Int64.MinValue; i = 0; foreach (Record rec in intIndex) { Debug.Assert(rec.intKey >= key); key = rec.intKey; i += 1; } Debug.Assert(i == nRecords); i = 0; String strKey = ""; foreach (Record rec in strIndex) { Debug.Assert(rec.strKey.CompareTo(strKey) >= 0); strKey = rec.strKey; i += 1; } Debug.Assert(i == nRecords); System.Console.WriteLine("Elapsed time for iteration through " + (nRecords * 2) + " records: " + (DateTime.Now - start)); Hashtable map = db.GetMemoryDump(); Console.WriteLine("Memory usage"); start = DateTime.Now; foreach (MemoryUsage usage in db.GetMemoryDump().Values) { Console.WriteLine(" " + usage.type.Name + ": instances=" + usage.nInstances + ", total size=" + usage.totalSize + ", allocated size=" + usage.allocatedSize); } Console.WriteLine("Elapsed time for memory dump: " + (DateTime.Now - start)); start = System.DateTime.Now; key = 1999; for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; #if USE_GENERICS Record rec = intIndex[key]; #else Record rec = (Record)intIndex[key]; #endif intIndex.Remove(rec); strIndex.Remove(rec); rec.Deallocate(); } System.Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start)); db.Close(); }