<s> import unittest <EOL> import os <EOL> import gc <EOL> import itertools <EOL> from time import time <EOL> from random import random <EOL> from tempfile import mkdtemp <EOL> import shutil <EOL> from rdflib . term import URIRef <EOL> from rdflib . graph import Graph <EOL> def random_uri ( ) : <EOL> return URIRef ( "<STR_LIT:%s>" % random ( ) ) <EOL> class StoreTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> store = '<STR_LIT:default>' <EOL> tmppath = None <EOL> configString = os . environ . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def setUp ( self ) : <EOL> self . gcold = gc . isenabled ( ) <EOL> gc . collect ( ) <EOL> gc . disable ( ) <EOL> self . graph = Graph ( store = self . store ) <EOL> if self . store == "<STR_LIT>" : <EOL> from rdflib . store . MySQL import MySQL <EOL> path = self . configString <EOL> MySQL ( ) . destroy ( path ) <EOL> else : <EOL> self . tmppath = mkdtemp ( ) <EOL> self . graph . open ( self . tmppath , create = True ) <EOL> self . input = input = Graph ( ) <EOL> input . parse ( "<STR_LIT>" ) <EOL> def tearDown ( self ) : <EOL> self . graph . close ( ) <EOL> if self . gcold : <EOL> gc . enable ( ) <EOL> del self . graph <EOL> shutil . rmtree ( self . tmppath ) <EOL> def testTime ( self ) : <EOL> number = <NUM_LIT:1> <EOL> print self . store <EOL> print "<STR_LIT>" , <EOL> for i in itertools . repeat ( None , number ) : <EOL> self . _testInput ( ) <EOL> print "<STR_LIT>" , <EOL> for i in itertools . repeat ( None , number ) : <EOL> self . _testRandom ( ) <EOL> print "<STR_LIT:.>" <EOL> def _testRandom ( self ) : <EOL> number = len ( self . input ) <EOL> store = self . graph <EOL> def add_random ( ) : <EOL> s = random_uri ( ) <EOL> p = random_uri ( ) <EOL> o = random_uri ( ) <EOL> store . add ( ( s , p , o ) ) <EOL> it = itertools . repeat ( None , number ) <EOL> t0 = time ( ) <EOL> for _i in it : <EOL> add_random ( ) <EOL> t1 = time ( ) <EOL> print "<STR_LIT>" % ( t1 - t0 ) , <EOL> def _testInput ( self ) : <EOL> number = <NUM_LIT:1> <EOL> store = self . graph <EOL> def add_from_input ( ) : <EOL> for t in self . input : <EOL> store . add ( t ) <EOL> it = itertools . repeat ( None , number ) <EOL> t0 = time ( ) <EOL> for _i in it : <EOL> add_from_input ( ) <EOL> t1 = time ( ) <EOL> print "<STR_LIT>" % ( t1 - t0 ) , <EOL> class MemoryStoreTestCase ( StoreTestCase ) : <EOL> store = "<STR_LIT>" <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
