benchmark/edge_lookup.cc
author deba
Tue, 17 Oct 2006 10:42:19 +0000
changeset 2246 9c472eee236f
parent 2240 d93c034d3c98
child 2252 133028e83940
permissions -rw-r--r--
Documentation is moved to source file
alpar@2238
     1
#include"edge_lookup_test.h"
alpar@2235
     2
#include<lemon/smart_graph.h>
alpar@2235
     3
#include<vector>
alpar@2235
     4
#include<lemon/time_measure.h>
deba@2242
     5
#include<lemon/random.h>
alpar@2235
     6
alpar@2235
     7
using namespace lemon;
alpar@2235
     8
alpar@2235
     9
GRAPH_TYPEDEFS(SmartGraph)
alpar@2235
    10
typedef SmartGraph Graph;
alpar@2235
    11
alpar@2235
    12
class FE 
alpar@2235
    13
{
alpar@2235
    14
public:
alpar@2235
    15
  Graph &_g;
alpar@2235
    16
  FE(Graph &g) :_g(g) {}
alpar@2235
    17
  void operator()() 
alpar@2235
    18
  {
alpar@2235
    19
    Edge e;
alpar@2235
    20
    
alpar@2235
    21
    for(NodeIt v(_g);v!=INVALID;++v)
alpar@2235
    22
      for(NodeIt u(_g);u!=INVALID;++u)
alpar@2235
    23
	e=findEdge(_g,u,v);
alpar@2235
    24
  }
alpar@2235
    25
  
alpar@2235
    26
};
alpar@2235
    27
alpar@2235
    28
class EL 
alpar@2235
    29
{
alpar@2235
    30
public:
alpar@2235
    31
  Graph &_g;
alpar@2235
    32
  EdgeLookUp<Graph> _el;
alpar@2235
    33
  EL(Graph &g) :_g(g), _el(g) {}
alpar@2235
    34
  void operator()() 
alpar@2235
    35
  {
alpar@2235
    36
    Edge e;
alpar@2235
    37
    
alpar@2235
    38
    for(NodeIt v(_g);v!=INVALID;++v)
alpar@2235
    39
      for(NodeIt u(_g);u!=INVALID;++u)
alpar@2235
    40
	e=_el(u,v);
alpar@2235
    41
  }
alpar@2235
    42
  
alpar@2235
    43
};
alpar@2235
    44
class EL2
alpar@2235
    45
{
alpar@2235
    46
public:
alpar@2235
    47
  Graph &_g;
alpar@2235
    48
  EdgeLookUp2<Graph> _el;
alpar@2235
    49
  EL2(Graph &g) :_g(g), _el(g) {}
alpar@2235
    50
  void operator()() 
alpar@2235
    51
  {
alpar@2235
    52
    Edge e;
alpar@2235
    53
    
alpar@2235
    54
    for(NodeIt v(_g);v!=INVALID;++v)
alpar@2235
    55
      for(NodeIt u(_g);u!=INVALID;++u)
alpar@2235
    56
	e=_el(u,v);
alpar@2235
    57
  }
alpar@2235
    58
  
alpar@2235
    59
};
alpar@2235
    60
alpar@2235
    61
class EL3
alpar@2235
    62
{
alpar@2235
    63
public:
alpar@2235
    64
  Graph &_g;
alpar@2235
    65
  EdgeLookUp3<Graph> _el;
alpar@2235
    66
  EL3(Graph &g) :_g(g), _el(g) {}
alpar@2235
    67
  void operator()() 
alpar@2235
    68
  {
alpar@2235
    69
    Edge e;
alpar@2235
    70
    
alpar@2235
    71
    for(NodeIt v(_g);v!=INVALID;++v)
alpar@2235
    72
      for(NodeIt u(_g);u!=INVALID;++u)
alpar@2235
    73
	e=_el(u,v);
alpar@2235
    74
  }
alpar@2235
    75
  
alpar@2235
    76
};
alpar@2235
    77
alpar@2240
    78
// class EL4
alpar@2240
    79
// {
alpar@2240
    80
// public:
alpar@2240
    81
//   Graph &_g;
alpar@2240
    82
//   EdgeLookUp4<Graph> _el;
alpar@2240
    83
//   EL4(Graph &g) :_g(g), _el(g) {}
alpar@2240
    84
//   void operator()() 
alpar@2240
    85
//   {
alpar@2240
    86
//     Edge e;
alpar@2235
    87
    
alpar@2240
    88
//     for(NodeIt v(_g);v!=INVALID;++v)
alpar@2240
    89
//       for(NodeIt u(_g);u!=INVALID;++u)
alpar@2240
    90
// 	e=_el(u,v);
alpar@2240
    91
//   }
alpar@2235
    92
  
alpar@2240
    93
// };
alpar@2235
    94
alpar@2238
    95
int main(int, char**argv)
alpar@2235
    96
{
alpar@2235
    97
  int N=atoi(argv[1]);
alpar@2235
    98
  int M=int(N*atof(argv[2]));
alpar@2235
    99
  
alpar@2235
   100
  Graph g;
alpar@2235
   101
  
alpar@2235
   102
  std::vector<Node> v;
alpar@2235
   103
  for(int i=0;i<N;i++) v.push_back(g.addNode());
deba@2242
   104
  for(int i=0;i<M;i++) g.addEdge(v[rnd[N]],v[rnd[N]]);
alpar@2235
   105
alpar@2235
   106
//   {
alpar@2235
   107
//     Edge e;
alpar@2235
   108
    
alpar@2235
   109
//     TimeReport t("findEdge: ");
alpar@2235
   110
//     for(NodeIt u(g);u!=INVALID;++u)
alpar@2235
   111
//       for(NodeIt v(g);v!=INVALID;++v)
alpar@2235
   112
// 	e=findEdge(g,u,v);
alpar@2235
   113
//   }
alpar@2235
   114
//   {
alpar@2235
   115
//     Edge e;
alpar@2235
   116
//     EdgeLookUp<Graph> el(g);
alpar@2235
   117
    
alpar@2235
   118
//     TimeReport t("EdgeLookUp: ");
alpar@2235
   119
//     for(NodeIt u(g);u!=INVALID;++u)
alpar@2235
   120
//       for(NodeIt v(g);v!=INVALID;++v)
alpar@2235
   121
// 	e=el(u,v);
alpar@2235
   122
//   }
alpar@2235
   123
alpar@2235
   124
alpar@2235
   125
  TimeStamp t1 = runningTimeTest(FE(g),1);
alpar@2235
   126
  TimeStamp t2 = runningTimeTest(EL(g),1);
alpar@2235
   127
  TimeStamp t3 = runningTimeTest(EL2(g),1);
alpar@2235
   128
  TimeStamp t4 = runningTimeTest(EL3(g),1);
alpar@2240
   129
//   TimeStamp t5 = runningTimeTest(EL4(g),1);
alpar@2235
   130
alpar@2235
   131
  std::cout << t1.userTime()/N/N << ' ' 
alpar@2235
   132
	    << t2.userTime()/N/N << ' '
alpar@2235
   133
	    << t3.userTime()/N/N << ' '
alpar@2235
   134
	    << t4.userTime()/N/N << ' '
alpar@2240
   135
// 	    << t5.userTime()/N/N
alpar@2240
   136
	    << std::endl;
alpar@2235
   137
}
alpar@2235
   138