We just had a discussion on the mailing list about blocked views. I have just updated my documentation

http://jura.wi.mit.edu/people/kelley/tutorial/python.html

here is a small sample code loading 1,000,000 entries (just a integer and corresponding binary data) I hadn't really used blocked views before, but the results are very impressive. The example I give orders the view on the first integer key. This is metakit speak for the first key is an ordered property and lookups are nlogn on that key.

First the output:
46.3960000277 seconds to load 1000000 entries
0.0600000619888 seconds to lookup up 1000 random entries
or 6.00000619888e-005 seconds per lookup

Now the code:
import metakit, random, time
st = metakit.storage("test.mk", 1)
# create a blocked view and
# order the view on the first integer value for lookup purposes
vw = st.getas("large_view[_B[key:I,data:B]]").blocked().ordered(1)

t1 = time.time()
for i in range(1000000):
   vw.append((i, str(i)))
   if i % 10000 == 0:
       # commit every 10000 entries
       print i
       st.commit()
t2 = time.time()
st.commit()
print (t2-t1), "seconds to load", len(vw), "entries"

# now test lookup times
lookup = []
size = len(vw)
for i in range(1000):
   lookup.append(int(random.random()*size))

t1 = time.time()
for i in lookup:
   vw.find(key=i)
t2 = time.time()
print (t2-t1), "seconds to lookup up", len(lookup), "random entries"
print "or", (t2-t1)/len(lookup), "seconds per lookup"

_____________________________________________
Metakit mailing list  -  [EMAIL PROTECTED]
http://www.equi4.com/mailman/listinfo/metakit

Reply via email to