Skip to content

Instantly share code, notes, and snippets.

@whardier
Created January 8, 2012 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whardier/ad2accc5b4655753923d to your computer and use it in GitHub Desktop.
Save whardier/ad2accc5b4655753923d to your computer and use it in GitHub Desktop.
import time
import os
import xapian
import uuid
uuid_blank = '00000000-0000-0000-0000-000000000000'
uuid_list = [str(uuid.uuid1()) for i in range(0,100000)]
unalloced = xapian.WritableDatabase('unalloced', xapian.DB_CREATE_OR_OPEN)
prealloced = xapian.WritableDatabase('prealloced', xapian.DB_CREATE_OR_OPEN)
docs = []
c = 1000
for i in range(1,c):
doc = xapian.Document()
doc.add_boolean_term(str(i))
unalloced.replace_document(i, doc)
docs.append(doc)
if i % 100 == 0:
print 'unallocated', i
unalloced.flush()
unalloced.close()
print 'flushing unalloc'
for i in range(1,c):
doc = xapian.Document()
doc.add_boolean_term(str(i))
for j in range(1,10000):
doc.add_value(j, uuid_blank)
prealloced.replace_document(i, doc)
if i % 100 == 0:
print 'preallocated', i
prealloced.flush()
prealloced.close()
print 'flushing prealloced'
time.sleep(1)
unalloced = xapian.WritableDatabase('unalloced', xapian.DB_CREATE_OR_OPEN)
prealloced = xapian.WritableDatabase('prealloced', xapian.DB_CREATE_OR_OPEN)
for i in range(1,c):
for j in range(1,10000):
docs[i-1].add_value(j, uuid_list[j])
print time.time()
for i in range(1,c):
unalloced.replace_document(i, docs[i-1])
unalloced.flush()
print time.time()
print "done with unalloced"
print time.time()
for i in range(1,c):
prealloced.replace_document(i, docs[i-1])
prealloced.flush()
print time.time()
print "done with prealloced"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment