If you have better test results, please tell me, my email: [email protected] , this article should be used as a starting point.
There is no need to indicate the source for reprinting, just repost it as you like.
Oracle Berkeley DB basics: http://www.oracle.com/technology/products/berkeley-db/index.html
Berkeley DB's official blog in China: Oracle Berkeley DB China R&D team's blog» A preliminary exploration of BDB C# API
The official website of the C# version of the BDB performance test program says that it can reach 45,748 items/s on XP sp3, but it is not written in C# and is probably faster. Here are the results of my test:
Intel single-core 2.8G, 2G on this machine, about 15337 lines/S,
Server Xeon quad-core, about 47,746 entries/S,
It is almost impossible to find C# performance testing programs on the Internet, and there are very few examples. It is recommended that you take a look at Berkeley DB’s official Chinese blog address: Oracle Berkeley DB China R&D Team’s Blog » BDB C# API Preliminary Study
The following is the BDB C# version test core program written by my brother. You can refer to it.
code
using System;
using System.Collections.Generic;
using System.Text;
using BerkeleyDB;
public class BRBDBDefault : IDisposable
{
BTreeDatabaseConfig btreeDBConfig;
BTreeDatabase btreeDB;
public BRBDBDefault() : this("bdb.db") { }
public BRBDBDefault(string dbName)
{
btreeDBConfig = new BTreeDatabaseConfig();
btreeDBConfig.Duplicates = DuplicatesPolicy.SORTED;
btreeDBConfig.Creation = CreatePolicy.IF_NEEDED; //Create the database if it does not exist
btreeDBConfig.PageSize = 4 * 1024; //Page size
btreeDBConfig.CacheSize = new CacheInfo(0, 1024 * 1024 * 80, 0);//Cache size
btreeDB = BTreeDatabase.Open(dbName, btreeDBConfig);
}
public void SetData(int id, string data)
{
DatabaseEntry k = new DatabaseEntry();
DatabaseEntry d = new DatabaseEntry();
k.Data = BitConverter.GetBytes(id);
d.Data = ASCIIEncoding.ASCII.GetBytes(data);
try
{
btreeDB.Put(k, d);
}
catch (System.AccessViolationException av)
{
}
catch { }
}
public void SetData(string id, string data)
{
DatabaseEntry k = new DatabaseEntry();
DatabaseEntry d = new DatabaseEntry();
k.Data = ASCIIEncoding.ASCII.GetBytes(id);
d.Data = ASCIIEncoding.ASCII.GetBytes(data);
try
{
btreeDB.Put(k, d);
}
catch (System.AccessViolationException av)
{
}
catch { }
}
public string GetData(int id)
{
DatabaseEntry de = new DatabaseEntry();
de.Data = BitConverter.GetBytes(id);
KeyValuePair<DatabaseEntry, DatabaseEntry> pair = btreeDB.Get(de);
if (pair.Value != null)
return ASCIIEncoding.ASCII.GetString(pair.Value.Data);
return string.Empty;
}
public string GetData(string id)
{
DatabaseEntry de = new DatabaseEntry();
de.Data = ASCIIEncoding.ASCII.GetBytes(id);
KeyValuePair<DatabaseEntry, DatabaseEntry> pair = btreeDB.Get(de);
if (pair.Value != null)
return ASCIIEncoding.ASCII.GetString(pair.Value.Data);
return string.Empty;
}
public string GetDBPath()
{
return btreeDB.FileName + btreeDB.DatabaseName;
}
#region IDisposable members
public void Close()
{
btreeDB.Close();
}
public void Dispose()
{
if (btreeDB != null) btreeDB.Dispose();
}
#endregion
}
Regarding the establishment of the test environment, please read the official blog for yourself, which is very detailed. The front-end test code is no longer sticky, just a cycle statistics time,
It is recommended that everyone use Lao Zhao’s CodeTimer