Le programme C# client pour tester LMDB

Je dois admettre que les aller/retour C#/LMDBDLL64.dll sont rapides… C’était ma crainte. Voir le post précédent pour obtenir les valeurs de performance.

Download de la DLL LMDB et du wrapper .NET ici.

        static void Main(string[] args)
        {
            Logger.LogInfo("Main...");
            //Main2()
            int count = 0;
            if (args.Length == 1)
            {
                count = Convert.ToInt32(args[0]);
            }

            string str = String.Format("count={0}", count);
            Logger.LogInfo(str);

            LightningEnvironment _env;
            LightningTransaction _txn;
            string dir = "c:\\temp\\cache_net10A";
            _env = new LightningEnvironment(dir);
            //This is here to assert that previous issues with the way manager
            //classes (since removed) worked don't happen anymore.
            _env.MaxDatabases = 2;
            _env.MapSize = 10485760 * 100;
            _env.Open();

            DateTime dtStart = DateTime.Now;
            var tx = _env.BeginTransaction();
            var db = tx.OpenDatabase("DB", new DatabaseConfiguration { Flags = DatabaseOpenFlags.Create });
            for (int i = 0; i < count; i++)
            {
                string key = String.Format("key_{0}", i);
                string value = String.Format("value_{0}", i);

                tx.Put(db, key, value);
            }

            tx.Put(db, "hello", "world");
            tx.Commit();
            db.Dispose();
            DateTime dtStop = DateTime.Now;
            TimeSpan ts = dtStop - dtStart;
            str = String.Format("Time elapsed:{0} ms", ts.TotalMilliseconds);
            Logger.LogInfo(str);

            tx = _env.BeginTransaction(TransactionBeginFlags.ReadOnly);
            db = tx.OpenDatabase("DB");
            var result = tx.Get(db, "hello");
            Logger.LogInfo(result);
            tx.Dispose();

            _env.Dispose();
        }

 

Leave a Reply

Your email address will not be published. Required fields are marked *