bdb.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python
  2. import sys
  3. from uuid import uuid4
  4. import arrow
  5. from rdflib import Dataset
  6. from rdflib.term import URIRef
  7. default_n = 100000
  8. sys.stdout.write('How many resources? [{}] >'.format(default_n))
  9. choice = input().lower()
  10. n = int(choice) if choice else default_n
  11. ds = Dataset('Sleepycat')
  12. ds.open('/tmp/lsup_bdb.db')
  13. gr = ds.graph('http://ex.org/graph#g1')
  14. start = arrow.utcnow()
  15. ckpt = start
  16. for i in range(1, n):
  17. if i % 100 == 0:
  18. print('inserted {} resources.'.format(i))
  19. subj = URIRef('http://ex.org/rdf/{}'.format(uuid4()))
  20. gr.add((subj, URIRef('http://ex.org/p1'), URIRef('http://ex.org/o1')))
  21. gr.add((URIRef('http://ex.org/s1'), URIRef('http://ex.org/p2'), subj))
  22. now = arrow.utcnow()
  23. tdelta = now - ckpt
  24. ckpt = now
  25. print('Record: {}\tTime elapsed: {}'.format(i, tdelta))
  26. tdelta = arrow.utcnow() - start
  27. print('Total elapsed time: {}'.format(tdelta))
  28. print('Average time per resource: {}'.format(tdelta.total_seconds()/n))
  29. print('Graph size: {}'.format(len(gr)))
  30. ds.close()