summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2013-01-20 10:50:37 +0000
committerLars Wirzenius <liw@liw.fi>2013-01-20 10:50:37 +0000
commit669695c1fb3bdc8f6a169ddd2c1eb2bf10fb6833 (patch)
treec927ec8c68067e0b8603b2953da27c2ab5b25aa4
parent206fb1529bf3bef9c51e9c47dd5b3fa053c485ba (diff)
parent42d9d6c7d048580e06cab7003db5fdd61a0a3f11 (diff)
downloadlarch-669695c1fb3bdc8f6a169ddd2c1eb2bf10fb6833.tar.gz
Fix speed-test
-rw-r--r--NEWS4
-rw-r--r--example.py17
-rw-r--r--larch/forest_tests.py3
-rw-r--r--larch/nodestore.py3
-rw-r--r--larch/nodestore_disk.py3
-rw-r--r--larch/nodestore_memory.py5
-rw-r--r--larch/nodestore_memory_tests.py3
-rw-r--r--larch/tree_tests.py9
-rwxr-xr-xspeed-test20
9 files changed, 43 insertions, 24 deletions
diff --git a/NEWS b/NEWS
index ec217b1..02d4494 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,10 @@ Version UNRELEASED
deleting references to them.
* Node numbers are now reported in hexadecimal, to make it easier to find
on disk. Patch by Damien Couroussé.
+* The `speed-test` script now works again. The initialiser API for
+ `NodeStore` and `NodeStoreMemory` now have a new first argument,
+ `allow_writes`, to make them compatible with the `NodeStoreDisk`
+ initialiser. Patch by Antoine Brenner.
Version 1.20121216
------------------
diff --git a/example.py b/example.py
index 53864c9..9161b0e 100644
--- a/example.py
+++ b/example.py
@@ -33,12 +33,13 @@ def compute(filename):
return md5.hexdigest()
-def open_tree(dirname):
+def open_tree(allow_writes, dirname):
key_size = len(compute('/dev/null'))
node_size = 4096
- forest = larch.open_forest(key_size=key_size, node_size=node_size,
- dirname=dirname)
+ forest = larch.open_forest(
+ allow_writes=allow_writes, key_size=key_size, node_size=node_size,
+ dirname=dirname)
if forest.trees:
tree = forest.trees[0]
else:
@@ -47,7 +48,7 @@ def open_tree(dirname):
def add(filenames):
- forest, tree = open_tree('example.tree')
+ forest, tree = open_tree(allow_writes=True, dirname='example.tree')
for filename in filenames:
checksum = compute(filename)
tree.insert(checksum, filename)
@@ -55,17 +56,17 @@ def add(filenames):
def find(checksums):
- forest, tree = open_tree('example.tree')
+ forest, tree = open_tree(allow_writes=False, dirname='example.tree')
for checksum in checksums:
filename = tree.lookup(checksum)
print checksum, filename
def list_checksums():
- forest, tree = open_tree('example.tree')
+ forest, tree = open_tree(allow_writes=False, dirname='example.tree')
key_size = len(compute('/dev/null'))
- minkey = '00' * key_size
- maxkey = 'ff' * key_size
+ minkey = '0' * key_size
+ maxkey = 'f' * key_size
for checksum, filename in tree.lookup_range(minkey, maxkey):
print checksum, filename
diff --git a/larch/forest_tests.py b/larch/forest_tests.py
index 9a786bd..b390844 100644
--- a/larch/forest_tests.py
+++ b/larch/forest_tests.py
@@ -26,7 +26,8 @@ class ForestTests(unittest.TestCase):
def setUp(self):
self.codec = larch.NodeCodec(3)
- self.ns = larch.NodeStoreMemory(64, self.codec)
+ self.ns = larch.NodeStoreMemory(
+ allow_writes=True, node_size=64, codec=self.codec)
self.forest = larch.Forest(self.ns)
def test_new_node_ids_grow(self):
diff --git a/larch/nodestore.py b/larch/nodestore.py
index 929450a..dd9b536 100644
--- a/larch/nodestore.py
+++ b/larch/nodestore.py
@@ -98,7 +98,8 @@ class NodeStore(object): # pragma: no cover
'''
- def __init__(self, node_size, codec):
+ def __init__(self, allow_writes, node_size, codec):
+ self.allow_writes = allow_writes
self.node_size = node_size
self.codec = codec
self.max_value_size = (node_size / 2) - codec.leaf_header.size
diff --git a/larch/nodestore_disk.py b/larch/nodestore_disk.py
index 197a411..6e8cd2f 100644
--- a/larch/nodestore_disk.py
+++ b/larch/nodestore_disk.py
@@ -117,7 +117,8 @@ class NodeStoreDisk(larch.NodeStore):
if format is not None:
tracing.trace('forcing format_base: %s', format)
self.format_base = format
- larch.NodeStore.__init__(self, node_size, codec)
+ larch.NodeStore.__init__(
+ self, allow_writes=allow_writes, node_size=node_size, codec=codec)
self.dirname = dirname
self.metadata_name = os.path.join(dirname, 'metadata')
self.metadata = None
diff --git a/larch/nodestore_memory.py b/larch/nodestore_memory.py
index 510ce5e..9ba2b02 100644
--- a/larch/nodestore_memory.py
+++ b/larch/nodestore_memory.py
@@ -26,8 +26,9 @@ class NodeStoreMemory(larch.NodeStore):
'''
- def __init__(self, node_size, codec):
- larch.NodeStore.__init__(self, node_size, codec)
+ def __init__(self,allow_writes, node_size, codec):
+ larch.NodeStore.__init__(
+ self, allow_writes=allow_writes, node_size=node_size, codec=codec)
self.nodes = dict()
self.refcounts = dict()
self.metadata = dict()
diff --git a/larch/nodestore_memory_tests.py b/larch/nodestore_memory_tests.py
index eecb905..56e3806 100644
--- a/larch/nodestore_memory_tests.py
+++ b/larch/nodestore_memory_tests.py
@@ -25,5 +25,6 @@ class NodeStoreMemoryTests(unittest.TestCase, larch.NodeStoreTests):
def setUp(self):
self.node_size = 4096
self.codec = larch.NodeCodec(self.key_bytes)
- self.ns = nodestore_memory.NodeStoreMemory(self.node_size, self.codec)
+ self.ns = nodestore_memory.NodeStoreMemory(
+ allow_writes=True, node_size=self.node_size, codec=self.codec)
diff --git a/larch/tree_tests.py b/larch/tree_tests.py
index 86895f0..2fee2d5 100644
--- a/larch/tree_tests.py
+++ b/larch/tree_tests.py
@@ -67,7 +67,8 @@ class BTreeTests(unittest.TestCase):
# We use a small node size so that all code paths are traversed
# during testing. Use coverage.py to make sure they do.
self.codec = larch.NodeCodec(3)
- self.ns = DummyNodeStore(64, self.codec)
+ self.ns = DummyNodeStore(
+ allow_writes=True, node_size=64, codec=self.codec)
self.forest = DummyForest()
self.tree = larch.BTree(self.forest, self.ns, None)
self.dump = False
@@ -549,7 +550,8 @@ class BTreeDecrementTests(unittest.TestCase):
# We use a small node size so that all code paths are traversed
# during testing. Use coverage.py to make sure they do.
self.codec = larch.NodeCodec(3)
- self.ns = DummyNodeStore(64, self.codec)
+ self.ns = DummyNodeStore(
+ allow_writes=True, node_size=64, codec=self.codec)
self.forest = DummyForest()
self.tree = larch.BTree(self.forest, self.ns, None)
self.tree.insert('foo', 'bar')
@@ -574,7 +576,8 @@ class BTreeDecrementTests(unittest.TestCase):
class BTreeBalanceTests(unittest.TestCase):
def setUp(self):
- ns = DummyNodeStore(4096, larch.NodeCodec(2))
+ ns = DummyNodeStore(
+ allow_writes=True, node_size=4096, codec=larch.NodeCodec(2))
forest = DummyForest()
self.tree = larch.BTree(forest, ns, None)
self.keys = ['%02d' % i for i in range(10)]
diff --git a/speed-test b/speed-test
index 5351a82..4fc5a24 100755
--- a/speed-test
+++ b/speed-test
@@ -15,8 +15,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Excercise my B-tree implementation, for simple benchmarking purposes.
-# The benchmark gets a location and an operation count as command line
-# arguments.
+# The benchmark gets a location and nb of keys to use as command line
+# arguments --location=LOCATION and --keys=KEYS.
#
# If the location is the empty string, an in-memory node store is used.
# Otherwise it must be a non-existent directory name.
@@ -73,14 +73,16 @@ class SpeedTest(cliapp.Application):
raise Exception('You must set number of keys with --keys')
if not location:
- forest = larch.open_forest(key_size=key_size, node_size=node_size,
- node_store=larch.NodeStoreMemory)
+ forest = larch.open_forest(
+ allow_writes=True, key_size=key_size, node_size=node_size,
+ node_store=larch.NodeStoreMemory)
else:
if os.path.exists(location):
raise Exception('%s exists already' % location)
os.mkdir(location)
- forest = larch.open_forest(key_size=key_size, node_size=node_size,
- dirname=location)
+ forest = larch.open_forest(
+ allow_writes=True, key_size=key_size, node_size=node_size,
+ dirname=location)
tree = forest.new_tree()
@@ -144,7 +146,11 @@ class SpeedTest(cliapp.Application):
# Report
def speed(result, i):
- return n / (result[i] - looptime[i])
+ if result[i] == looptime[i]:
+ # computer too fast for the number of "keys" used...
+ return float("infinity")
+ else:
+ return n / (result[i] - looptime[i])
def report(label, result):
cpu, wall = result
print '%-16s: %5.3f s (%8.1f/s) CPU; %5.3f s (%8.1f/s) wall' % \