Back to index

python-biopython  1.60
biosql_performance_load.py
Go to the documentation of this file.
00001 #/usr/bin/env python
00002 """Small script to test timing of loading records into a BioSQL database.
00003 """
00004 import time
00005 # set up the connection
00006 from Bio import GenBank
00007 from BioSQL import BioSeqDatabase
00008 server = BioSeqDatabase.open_database (host = "192.168.0.192", user = "root", 
00009                                        passwd = "", db = "pythonloadtest")
00010 
00011 # remove the database if it already exists
00012 db_name = "testload"
00013 try:
00014     server[db_name]
00015     server.remove_database(db_name)
00016 except KeyError:
00017     pass
00018 db = server.new_database(db_name)
00019 
00020 input_file = "/home/hack/install/biopython/Tests/GenBank/cor6_6.gb"
00021 handle = open(input_file, "r")
00022 parser = GenBank.FeatureParser()
00023 iterator = GenBank.Iterator(handle, parser)
00024 
00025 # -- do the timing part
00026 start_time = time.time()
00027 num_records = db.load(iterator)
00028 end_time = time.time()
00029 elapsed_time = end_time - start_time
00030 print "Loading"
00031 print "\tDid %s records in %s seconds for\n\t%f records per second" % \
00032       (num_records, elapsed_time, float(num_records) / float(elapsed_time))
00033