<s> """<STR_LIT>""" <EOL> import numpy <EOL> import logging <EOL> import time <EOL> import networkx <EOL> from apgl . graph import DenseGraph , SparseGraph , PySparseGraph , DictGraph <EOL> from exp . sandbox . graph . CsArrayGraph import CsArrayGraph <EOL> numpy . set_printoptions ( suppress = True , precision = <NUM_LIT:4> ) <EOL> class GraphIterator : <EOL> def __init__ ( self , numVertices , sparseOnly = False , numEdges = <NUM_LIT:0> ) : <EOL> self . numVertices = numVertices <EOL> self . sparseOnly = sparseOnly <EOL> self . graphList = [ ] <EOL> if not self . sparseOnly : <EOL> self . graphList . append ( DenseGraph ( numVertices ) ) <EOL> self . graphList . append ( PySparseGraph ( numVertices ) ) <EOL> self . graphList . append ( DictGraph ( ) ) <EOL> self . i = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> if self . i == len ( self . graphList ) : <EOL> raise StopIteration <EOL> else : <EOL> graph = self . graphList [ self . i ] <EOL> self . i += <NUM_LIT:1> <EOL> return graph <EOL> def getNumGraphs ( self ) : <EOL> return len ( self . graphList ) <EOL> def generateEdges ( ) : <EOL> edgeList = [ ] <EOL> density = <NUM_LIT> <EOL> numVertices = numpy . array ( [ <NUM_LIT:100> , <NUM_LIT:200> , <NUM_LIT> , <NUM_LIT:1000> ] ) <EOL> for i in numVertices : <EOL> numEdges = ( i ** <NUM_LIT:2> ) * density <EOL> edges = numpy . zeros ( ( numEdges , <NUM_LIT:2> ) ) <EOL> edges [ : , <NUM_LIT:0> ] = numpy . random . randint ( <NUM_LIT:0> , i , numEdges ) <EOL> edges [ : , <NUM_LIT:1> ] = numpy . random . randint ( <NUM_LIT:0> , i , numEdges ) <EOL> edgeList . append ( ( i , edges ) ) <EOL> return edgeList <EOL> def benchmark ( edgeList ) : <EOL> iterator = GraphIterator ( <NUM_LIT:100> ) <EOL> numGraphTypes = iterator . getNumGraphs ( ) <EOL> numMeasures = <NUM_LIT:6> <EOL> timeArray = numpy . zeros ( ( len ( edgeList ) , numGraphTypes , numMeasures ) ) <EOL> i = <NUM_LIT:0> <EOL> nxGraph = networkx . Graph ( ) <EOL> for numVertices , edges in edgeList : <EOL> print ( "<STR_LIT>" + str ( numVertices ) + "<STR_LIT>" + str ( edges . shape [ <NUM_LIT:0> ] ) + "<STR_LIT>" ) <EOL> iterator = GraphIterator ( numVertices ) <EOL> j = <NUM_LIT:0> <EOL> for graph in iterator : <EOL> measureInd = <NUM_LIT:0> <EOL> print ( "<STR_LIT>" + str ( graph ) ) <EOL> startTime = time . clock ( ) <EOL> for m in range ( <NUM_LIT:10> ) : <EOL> graph . addEdges ( edges ) <EOL> timeArray [ i , j , measureInd ] = time . clock ( ) - startTime <EOL> measureInd += <NUM_LIT:1> <EOL> vertexIds = graph . getAllVertexIds ( ) <EOL> print ( "<STR_LIT>" + str ( graph ) ) <EOL> startTime = time . clock ( ) <EOL> for m in range ( <NUM_LIT:100> ) : <EOL> for k in range ( <NUM_LIT:50> ) : <EOL> graph . neighbours ( vertexIds [ k ] ) <EOL> timeArray [ i , j , measureInd ] = time . clock ( ) - startTime <EOL> measureInd += <NUM_LIT:1> <EOL> print ( "<STR_LIT>" + str ( graph ) ) <EOL> startTime = time . clock ( ) <EOL> for k in range ( <NUM_LIT:5> ) : <EOL> graph . depthFirstSearch ( vertexIds [ k ] ) <EOL> timeArray [ i , j , measureInd ] = time . clock ( ) - startTime <EOL> measureInd += <NUM_LIT:1> <EOL> print ( "<STR_LIT>" + str ( graph ) ) <EOL> startTime = time . clock ( ) <EOL> for k in range ( <NUM_LIT:5> ) : <EOL> graph . breadthFirstSearch ( vertexIds [ k ] ) <EOL> timeArray [ i , j , measureInd ] = time . clock ( ) - startTime <EOL> measureInd += <NUM_LIT:1> <EOL> print ( "<STR_LIT>" + str ( graph ) ) <EOL> startTime = time . clock ( ) <EOL> graph . findConnectedComponents ( ) <EOL> timeArray [ i , j , measureInd ] = time . clock ( ) - startTime <EOL> measureInd += <NUM_LIT:1> <EOL> print ( "<STR_LIT>" + str ( graph ) ) <EOL> startTime = time . clock ( ) <EOL> for k in range ( <NUM_LIT:100> ) : <EOL> graph . degreeSequence ( ) <EOL> timeArray [ i , j , measureInd ] = time . clock ( ) - startTime <EOL> measureInd += <NUM_LIT:1> <EOL> j += <NUM_LIT:1> <EOL> i += <NUM_LIT:1> <EOL> return timeArray <EOL> edgeList = generateEdges ( ) <EOL> timeArray = benchmark ( edgeList ) <EOL> for i in range ( timeArray . shape [ <NUM_LIT:2> ] ) : <EOL> print ( timeArray [ : , : , i ] ) </s>
