?? testjsql.cs
字號:
using System;
#if USE_GENERICS
using System.Collections.Generic;
#else
using System.Collections;
#endif
using Perst;
using System.Diagnostics;
public class TestJSQL
{
public class Record:Persistent
{
public string strKey;
public long intKey;
}
public class Root:Persistent
{
#if USE_GENERICS
public FieldIndex<string,Record> strIndex;
public FieldIndex<long,Record> intIndex;
#else
public FieldIndex strIndex;
public FieldIndex intIndex;
#endif
}
internal const int nRecords = 100000;
internal static int pagePoolSize = 32 * 1024 * 1024;
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);
#else
root.strIndex = db.CreateFieldIndex(typeof(Record), "strKey", true);
root.intIndex = db.CreateFieldIndex(typeof(Record), "intKey", true);
#endif
db.Root = root;
}
#if USE_GENERICS
FieldIndex<string,Record> strIndex = root.strIndex;
FieldIndex<long,Record> intIndex = root.intIndex;
IEnumerator<Record> enumerator;
#else
FieldIndex intIndex = root.intIndex;
FieldIndex strIndex = root.strIndex;
IEnumerator enumerator;
#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;
}
db.Commit();
System.Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - 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=?");
#else
Query q1 = db.CreateQuery();
q1.Prepare(typeof(Record), "strKey=?");
Query q2 = db.CreateQuery();
q2.Prepare(typeof(Record), "intKey=?");
#endif
q1.AddIndex("strKey", strIndex);
q2.AddIndex("intKey", intIndex);
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;
key = 1999;
foreach (Record rec in intIndex)
{
rec.Deallocate();
}
intIndex.Deallocate();
strIndex.Deallocate();
System.Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start));
db.Close();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -