<s> from zen . util . benchmark import Benchmark <EOL> from random import random <EOL> import networkx as nx <EOL> import zen as zn <EOL> import igraph as ig <EOL> class NonRandomGraphBenchmark ( Benchmark ) : <EOL> def __init__ ( self ) : <EOL> Benchmark . __init__ ( self , '<STR_LIT>' ) <EOL> self . NUM_NODES = <NUM_LIT> <EOL> self . NUM_EDGES = <NUM_LIT> <EOL> def bm_igraph ( self ) : <EOL> G = ig . Graph ( ) <EOL> node_lookup = { } <EOL> G . add_vertices ( self . NUM_NODES ) <EOL> for i in range ( self . NUM_NODES ) : <EOL> node_lookup [ i ] = i <EOL> num_nodes = self . NUM_NODES <EOL> i = <NUM_LIT:0> <EOL> ni = <NUM_LIT:0> <EOL> nj = <NUM_LIT:1> <EOL> edges = [ ] <EOL> while i < self . NUM_EDGES : <EOL> edges . append ( ( ni , nj ) ) <EOL> i += <NUM_LIT:1> <EOL> nj += <NUM_LIT:1> <EOL> if nj >= num_nodes : <EOL> ni += <NUM_LIT:1> <EOL> nj = ni + <NUM_LIT:1> <EOL> G . add_edges ( edges ) <EOL> def bm_networkx ( self ) : <EOL> G = nx . Graph ( ) <EOL> for i in range ( self . NUM_NODES ) : <EOL> G . add_node ( i ) <EOL> num_nodes = self . NUM_NODES <EOL> i = <NUM_LIT:0> <EOL> ni = <NUM_LIT:0> <EOL> nj = <NUM_LIT:1> <EOL> while i < self . NUM_EDGES : <EOL> G . add_edge ( ni , nj ) <EOL> i += <NUM_LIT:1> <EOL> nj += <NUM_LIT:1> <EOL> if nj >= num_nodes : <EOL> ni += <NUM_LIT:1> <EOL> nj = ni + <NUM_LIT:1> <EOL> def bm_zen ( self ) : <EOL> G = zn . Graph ( ) <EOL> for i in range ( self . NUM_NODES ) : <EOL> G . add_node ( i ) <EOL> num_nodes = self . NUM_NODES <EOL> i = <NUM_LIT:0> <EOL> ni = <NUM_LIT:0> <EOL> nj = <NUM_LIT:1> <EOL> while i < self . NUM_EDGES : <EOL> G . add_edge ( ni , nj ) <EOL> i += <NUM_LIT:1> <EOL> nj += <NUM_LIT:1> <EOL> if nj >= num_nodes : <EOL> ni += <NUM_LIT:1> <EOL> nj = ni + <NUM_LIT:1> <EOL> def bm_zenopt ( self ) : <EOL> G = zn . Graph ( ) <EOL> G . add_nodes ( self . NUM_NODES ) <EOL> num_nodes = self . NUM_NODES <EOL> i = <NUM_LIT:0> <EOL> ni = <NUM_LIT:0> <EOL> nj = <NUM_LIT:1> <EOL> while i < self . NUM_EDGES : <EOL> G . add_edge_ ( ni , nj ) <EOL> i += <NUM_LIT:1> <EOL> nj += <NUM_LIT:1> <EOL> if nj >= num_nodes : <EOL> ni += <NUM_LIT:1> <EOL> nj = ni + <NUM_LIT:1> </s>
