C#中使用多款LevelDB.Net封装测试性能

一、使用http://www.nuget.org/packages/LevelDB.NET 测试

  1、新建项目,并Nuget引入库:

    C#中使用多款LevelDB.Net封装测试性能_第1张图片

  2、写代码

using LevelDB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LevelDBDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            WriteTest();
        }
        public static void WriteTest()
        {
            var db = LevelDB.DB.Open("c:\\works\\mydb", new Options { CreateIfMissing = true });

            System.Diagnostics.Stopwatch sp = new System.Diagnostics.Stopwatch();
            sp.Reset();
            sp.Start();
            long mCount = 0;
            while (true)
            {
                db.Put(WriteOptions.Default, Guid.NewGuid().ToString(), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaeraaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
                if (System.Threading.Interlocked.Increment(ref mCount) % 10000 == 0)
                {
                    Console.WriteLine("{0} has inserted. time use {1}ms.", mCount, sp.ElapsedMilliseconds);
                }
            }
        }
    }
}

  3、看效果:我的机器上配置不怎么好,大约5000条/秒。

10000 has inserted. time use 1968ms.
20000 has inserted. time use 3996ms.
30000 has inserted. time use 6032ms.
40000 has inserted. time use 7969ms.
50000 has inserted. time use 10465ms.
60000 has inserted. time use 12932ms.
70000 has inserted. time use 14914ms.
80000 has inserted. time use 17161ms.
90000 has inserted. time use 19351ms.
100000 has inserted. time use 21431ms.
110000 has inserted. time use 23572ms.
120000 has inserted. time use 25277ms.
130000 has inserted. time use 27174ms.
140000 has inserted. time use 29311ms.
150000 has inserted. time use 31577ms.
160000 has inserted. time use 33539ms.
170000 has inserted. time use 36045ms.
180000 has inserted. time use 37894ms.
190000 has inserted. time use 40296ms.
200000 has inserted. time use 42255ms.
210000 has inserted. time use 44752ms.
220000 has inserted. time use 46432ms.
230000 has inserted. time use 48524ms.
240000 has inserted. time use 50457ms.
250000 has inserted. time use 52648ms.
260000 has inserted. time use 54896ms.
270000 has inserted. time use 57293ms.
280000 has inserted. time use 59354ms.
290000 has inserted. time use 61576ms.
300000 has inserted. time use 63735ms.
310000 has inserted. time use 65710ms.
320000 has inserted. time use 67867ms.
330000 has inserted. time use 69724ms.
340000 has inserted. time use 71691ms.
350000 has inserted. time use 74123ms.
360000 has inserted. time use 76347ms.
370000 has inserted. time use 78387ms.
380000 has inserted. time use 80481ms.
390000 has inserted. time use 82766ms.
400000 has inserted. time use 84601ms.
410000 has inserted. time use 86751ms.
420000 has inserted. time use 88961ms.
430000 has inserted. time use 91061ms.
440000 has inserted. time use 93445ms.
450000 has inserted. time use 95739ms.
460000 has inserted. time use 97735ms.
470000 has inserted. time use 99911ms.
480000 has inserted. time use 102113ms.
490000 has inserted. time use 104124ms.
500000 has inserted. time use 106092ms.
510000 has inserted. time use 107903ms.
520000 has inserted. time use 112400ms.
530000 has inserted. time use 114539ms.
540000 has inserted. time use 339741ms.
550000 has inserted. time use 342317ms.
560000 has inserted. time use 344162ms.

 二、修改引用库:

  http://www.meebey.net/projects/leveldb-sharp/  

  https://github.com/meebey/leveldb-sharp

  注意,需要把leveldb.dll放在程序目录下。这个文件可以通过下载https://www.nuget.org/packages/LevelDB.Net/ 中的dll,然后反编译,取得里面的资源。C#中使用多款LevelDB.Net封装测试性能_第2张图片

 

  同时引入:C#中使用多款LevelDB.Net封装测试性能_第3张图片

 

  2、代码和前面的相同

  3、运行结果:

  C#中使用多款LevelDB.Net封装测试性能_第4张图片

  C#中使用多款LevelDB.Net封装测试性能_第5张图片

  效果还不错,大约是6.6w条/秒。

 

转载于:https://www.cnblogs.com/songxingzhu/p/6009556.html

你可能感兴趣的:(C#中使用多款LevelDB.Net封装测试性能)