Simple test of LEVELDB

Source: Internet
Author: User
1. Latest Version Download address https://code.google.com/p/leveldb/downloads/list
2. Put in the Linux system to extract and compile, in fact, compile leveldb is very simple, unzip the download package into the directory to directly execute make. Several files are generated in the current directory after compilation: LIBLEVELDB.A libleveldb.so libleveldb.so.1 libleveldb.so.1.13 (I am currently downloading the 1.13.0 version), where libleveldb.so.1,libleveldb.so are libleveldb.so.1.13 's soft connection
3. Compiling the performance test programThe source package comes with several performance test programs, one is LEVELDB's own test program: Db_bench, and two are Db_bench_sqlite3, db_bench_tree_db, respectively compiled make Db_bench make db_ Bench_sqlite3 Mke db_bench_tree_db, the back two because the dependency relationship does not necessarily compile and pass, the specific problem needs to be solved concretely.
4. Execute db_bench wait until the following data [Root@localhost leveldb-1.13.0]# ./db_bench  leveldb:    version 1.13 Date:       Wed Sep & Nbsp;4 11:51:30 CPU:        1 * Intel (R) Core (TM) i5 CPU       M 520  @ 2.40G Hz Cpucache:   3072 KB Keys:       bytes All Values:     bytes each (bytes Compression) Entries:    1000000 rawsize:    110.6 MB (estimated) FileSize:   62.9 MB (estimated) Warning:snappy compression is not enabled------------------------------------------------fillseq              :       3.783 micros/op;   29.2 MB/s      fillsync              :      3225.4 Micros/op;    0.0 MB/s (fillrandom)        :      11.218 micros/op;    9.9 MB/s      overwrite       &NBsp &NBSP:      18.988 micros/op;    5.8 MB/s      readrandom    :      12.606 micros/op; (1000000 of 1000000 found) readrandom    :       6.795 micros/op; (1000000 of 1000000 found) readseq            :       0.311 micros/op;  355.2 MB/s     readreverse      :       0.636 micros/op;  173.9 MB/s     compact            :    2563542.000 micros/op; Readrandom      :    4.043 micros/op; (1000000 of 1000000 found) readseq              :    0.269 micros/op;  411.3 MB/s     readreverse        :    0.566 micros/op;  195.4 MB/s     fill100k              :     6787.659 micros/op ;  14.1 MB/s (crc32c)                :     10.426 micros/op;  374.7 MB/s (4K per op) snappycomp    :     8702.000 micros/op; (Snappy failure) Snappyuncomp:    6969.000 micros/op; (Snappy failure) acquireload      :    1.493 micros/op; (each op was loads) is preceded by some information about the machine and the information to be written to it, followed by performance data, about micros/op its value is as small as possible, about MB/s the larger the better
5. Prepare the header file for developmentCopy the Leveldb directory under include to/usr/include/: Cp-r include/leveldb/usr/include/
6. Simple test CasesMain.cpp
#include <assert>
#include <iostream>
#include <leveldb/db.h>

int main (int Argc,char * Argv[])
{
	leveldb::D b* DB;
	Leveldb::options Options;
	Options.create_if_missing = true;
	std::string dbpath = "TestDB";
	Leveldb::status Status = leveldb::D b::open (Options, DBPath, &db);
	ASSERT (Status.ok ());
	std::string key = "Test";
	std::string val = "Test_value";
	s = Db->put (Leveldb::writeoptions (), Key, Val);
	Val.clear ();
	s = Db->get (Leveldb::readoptions (), key, &val);

	Std::cout << key << ":" << val << std::endl;
}

Compile: Copy the previously compiled LIBLEVELDB.A to the same directory as the above code and g++-O leveldbtest main.cpp libleveldb.a-lpthread

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.