Skip to content
Browse files

Add simple performance test that writes out 100k entries with each 1k…

… value.
  • Loading branch information...
1 parent afffdde commit c3fc65eae052d88039fa8339111b3ac6ac00a52f @krestenkrab committed Jan 21, 2011
Showing with 34 additions and 0 deletions.
  1. +3 −0 README.md
  2. +31 −0 src/test/java/com/trifork/bitcask/BitCaskTest.java
View
3 README.md
@@ -10,6 +10,9 @@ I'm doing this in order to
* Provide tools to be able to read (write?) bitcask files without using Erlang,
which could make people more comfortable with using the backend.
+bitcask-java tries to e faithful to the original bitcask, so it should be interoperable
+and be able to run concurrently with the original.
+
At this stage, you can create/open a bitcask and get/put data to it. For sample
usage see [BitCaskTest.java](https://github.com/krestenkrab/bitcask-java/blob/master/src/test/java/com/trifork/bitcask/BitCaskTest.java)
View
31 src/test/java/com/trifork/bitcask/BitCaskTest.java
@@ -79,6 +79,37 @@ public void wrapTest() throws Exception {
b.close();
}
+ @Test
+ public void perfTest() throws Exception {
+ runtest();
+ runtest();
+ }
+
+ private void runtest() throws IOException, InterruptedException, Exception {
+ int n = 1024 * 100;
+ ByteString data = ByteString.copyFrom(new byte[1000]);
+
+ File dirname = new File("/tmp/bc.test.perf");
+ rmdir(dirname);
+ BitCaskOptions opts = new BitCaskOptions();
+ opts.read_write = true;
+ BitCask b = BitCask.open(dirname, opts);
+
+ System.gc();
+ long before = System.currentTimeMillis();
+ for (int i = 0; i < n; i++) {
+ b.put(bs("k"+i), data);
+ }
+ long after = System.currentTimeMillis();
+ double secs = (after-before)/1000.00;
+
+ System.out.println(""+secs+" secs for writing "+n+" entries");
+ System.out.println(""+(1000.0*secs/n)+" ms per entry");
+
+ b.close();
+ }
+
+
/** utility that slurps an entire bitcask into a HashMap */
private Map<ByteString, ByteString> contents(BitCask b) throws IOException {
final Map<ByteString, ByteString> l = new HashMap<ByteString, ByteString>();

0 comments on commit c3fc65e

Please sign in to comment.
Something went wrong with that request. Please try again.