title: NetworkX average shortest path length and diameter is taking forever
body: <p>I have a graph (A) built from unweighted edges, and I would like to compute the average shortest path length for the biggest connected graph (giantC) in my main graph (A). However, the script has been running for more than 3 hours so far (tried on Colab and locally), and no results are output neither for <code>diameter</code> nor for <code>average_shortest_path_length</code>.</p>
  <p>I am using <code>networkx==2.5</code>, <code>python==3.6.9</code></p>
  <p>and here is my script</p>
  <pre><code>import logging
  import networkx as nx 
  from networkx.algorithms.distance_measures import diameter
  from networkx.algorithms.shortest_paths.generic import average_shortest_path_length
  
  
  # graph is built from a json file as follows 
  with open('graph.json') as f:
       graph_dict = json.load(f)
  
  _indices = graph_dict['indices']
  s_lst, rs_lst= _indices[0], _indices[1]    
  
  graph_ = nx.Graph()
  for i in range(len(s_lst)):
       graph_.add_edge(s_lst[i], rs_lst[i])
  
  
  # fetch the hugest graph of all graphs
  connected_subgraphs = [graph_.subgraph(cc) for cc in 
  nx.connected_components(graph_)]
  logging.info('connected subgraphs fetched.')
  Gcc = max(nx.connected_components(graph_), key=len)
  giantC = graph_.subgraph(Gcc)
  logging.info('Fetched Giant Subgraph')
  
  n_nodes = giantC.number_of_nodes()
  print(f'Number of nodes: {n_nodes}') # output is 106088
  
  avg_shortest_path = average_shortest_path_length(giantC)
  print(f'Avg Shortest path len: {avg_shortest_path}')
  
  dia = diameter(giantC)
  print(f'Diameter: {dia}')
  </code></pre>
  <p>Is there any way to make it faster? or an alternative to computing both the diameter and shortest path length for the giantC graph?</p>