[Lemon-commits] [lemon_svn] alpar: r999 - hugo/trunk/src/benchmark

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:42:39 CET 2006


Author: alpar
Date: Tue Jul 27 18:09:42 2004
New Revision: 999

Added:
   hugo/trunk/src/benchmark/bfs-bench.cc
Modified:
   hugo/trunk/src/benchmark/Makefile.am
   hugo/trunk/src/benchmark/bench_tools.h
   hugo/trunk/src/benchmark/benchmark
   hugo/trunk/src/benchmark/hcube.cc

Log:
- bfs-bench added
- hypercube generators moved to bench-tools.h
- new benchmark script


Modified: hugo/trunk/src/benchmark/Makefile.am
==============================================================================
--- hugo/trunk/src/benchmark/Makefile.am	(original)
+++ hugo/trunk/src/benchmark/Makefile.am	Tue Jul 27 18:09:42 2004
@@ -1,7 +1,9 @@
 AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/work  -I$(top_srcdir)/src/work/marci
 
-noinst_PROGRAMS = graph-bench hcube
+noinst_PROGRAMS = graph-bench hcube bfs-bench
 
 graph_bench_SOURCES = graph-bench.cc bench_tools.h
 
 hcube_SOURCES = hcube.cc bench_tools.h
+
+bfs_bench_SOURCES = bfs-bench.cc bench_tools.h

Modified: hugo/trunk/src/benchmark/bench_tools.h
==============================================================================
--- hugo/trunk/src/benchmark/bench_tools.h	(original)
+++ hugo/trunk/src/benchmark/bench_tools.h	Tue Jul 27 18:09:42 2004
@@ -81,6 +81,42 @@
 	    << S.getSystemTime() << ' ' << S.getRealTime() << std::endl;
 }
 
+
+
+///
+template<class Graph>
+void addHiperCube(Graph &G,int dim,std::vector<typename Graph::Node> &nodes)
+{
+  GRAPH_TYPEDEF_FACTORY(Graph);
+  
+  std::vector<int> bits(dim+1);
+  bits[0]=1;
+  for(int i=1;i<=dim;i++) bits[i]=2*bits[i-1];
+  
+  for(int i=0;i<bits[dim];i++) {
+    nodes.push_back(G.addNode());
+    for(int j=0;j<dim;j++) if(i&bits[j]) G.addEdge(nodes[i-bits[j]],nodes[i]);
+  }
+}
+
+///
+template<class Graph>
+void addBiDirHiperCube(Graph &G,int dim,std::vector<typename Graph::Node>&nodes)
+{
+  GRAPH_TYPEDEF_FACTORY(Graph);
+  
+  std::vector<int> bits(dim+1);
+  bits[0]=1;
+  for(int i=1;i<=dim;i++) bits[i]=2*bits[i-1];
   
+  for(int i=0;i<bits[dim];i++) {
+    nodes.push_back(G.addNode());
+    for(int j=0;j<dim;j++) if(i&bits[j]) {
+      G.addEdge(nodes[i-bits[j]],nodes[i]);
+      G.addEdge(nodes[i],nodes[i-bits[j]]);
+    }
+    
+  }
+}  
 
 #endif

Modified: hugo/trunk/src/benchmark/benchmark
==============================================================================
--- hugo/trunk/src/benchmark/benchmark	(original)
+++ hugo/trunk/src/benchmark/benchmark	Tue Jul 27 18:09:42 2004
@@ -3,7 +3,8 @@
 function runtest () # prefix, prog, args
 {
     echo $1 1>&2
-    for ((i=1;i<5;i++))
+    $2 $3 $4 $5 $6 $7 $8 $9;
+    for ((i=1;i<=5;i++))
       do
       $2 $3 $4 $5 $6 $7 $8 $9;
     done |

Added: hugo/trunk/src/benchmark/bfs-bench.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/src/benchmark/bfs-bench.cc	Tue Jul 27 18:09:42 2004
@@ -0,0 +1,127 @@
+// -*- mode:C++ -*-
+
+#include<math.h>
+#include<hugo/list_graph.h>
+#include<hugo/smart_graph.h>
+#include<hugo/dijkstra.h>
+#include<hugo/max_flow.h>
+
+#include"bench_tools.h"
+
+using namespace std;
+using namespace hugo;
+
+inline int numOfOnes(int n,int dim)
+{
+  int s=0;
+  for(int i=0;i<dim;i++) {
+    s+=n%2;
+    n>>=1;
+  }
+  return s;
+}
+
+inline int numOfZeros(int n,int dim)
+{
+  int s=dim;
+  for(int i=0;i<dim;i++) {
+    s-=n&1;
+    n>>=1;
+  }
+  return s;
+}
+
+template<class Graph>
+void bfsStlQueue(Graph &G,typename Graph::Node source)
+{
+  GRAPH_TYPEDEF_FACTORY(Graph);
+
+  using namespace std;
+  
+  typename Graph::NodeMap<bool> visited(G,false);
+    
+  queue<typename Graph::Node> Q;
+    
+  Q.push(source);
+  visited[source]=true;
+  do {
+    Node n(Q.front());
+    Node m;
+    Q.pop();
+    for(OutEdgeIt e(G,n);G.valid(e);G.next(e))
+      if(!visited[m=G.head(e)]) {
+	Q.push(m);
+	visited.set(m,true);
+      }
+  } while(!Q.empty());
+}
+
+template<class Graph>
+void bfsOwnQueue(Graph &G,typename Graph::Node source)
+{
+  GRAPH_TYPEDEF_FACTORY(Graph);
+
+  using namespace std;
+  
+  typename Graph::NodeMap<bool> visited(G,false);
+  
+  int N=G.nodeNum();
+  vector<typename Graph::Node> Q(N);
+  int Qh=0;
+  int Qt=0;
+  
+
+  Q[Qh++]=source;
+  visited.set(source,true);
+  do {
+    Node m;
+    Node n=Q[Qt++];
+    for(OutEdgeIt e(G,n);G.valid(e);G.next(e))
+      if(!visited[m=G.head(e)]) {
+	Q[Qh++]=m;
+	visited.set(m,true);
+      }
+  } while(Qt!=Qh);
+}
+
+int main(int argc, char *argv[])
+{
+  //  typedef ListGraph Graph;
+  typedef SmartGraph Graph;
+
+  ///\bug GRAPH_TYPEDEF_FACTORY(Graph);
+  GRAPH_TYPEDEF_FACTORY_NOTYPENAME(Graph);
+
+  Graph G;
+  
+  Timer T;
+  
+  if(argc!=2) {
+    cout << "Usage: " << argv[0] << " dim\n";
+    return 1;
+  }
+  
+  int dim=atoi(argv[1]);
+  
+//   cout << "Creating Hipercube ("<< (1<<dim) << " nodes, "
+//        << dim*(1<<dim) << " edges):";
+
+  T.reset();
+  vector<Node> nodes;
+  addBiDirHiperCube(G,dim,nodes);
+
+  PrintTime("GENGRAPH",T);
+
+  T.reset();
+  {
+    for(int i=0;i<50000;i++)
+      bfsStlQueue(G,nodes[0]);
+  }
+  PrintTime("BFS-STL",T);
+  T.reset();
+  {
+    for(int i=0;i<50000;i++)
+      bfsOwnQueue(G,nodes[0]);
+  }
+  PrintTime("BFS-OWN",T);
+}

Modified: hugo/trunk/src/benchmark/hcube.cc
==============================================================================
--- hugo/trunk/src/benchmark/hcube.cc	(original)
+++ hugo/trunk/src/benchmark/hcube.cc	Tue Jul 27 18:09:42 2004
@@ -11,40 +11,6 @@
 using namespace std;
 using namespace hugo;
 
-template<class Graph>
-void addHiperCube(Graph &G,int dim,vector<typename Graph::Node> &nodes)
-{
-  GRAPH_TYPEDEF_FACTORY(Graph);
-  
-  vector<int> bits(dim+1);
-  bits[0]=1;
-  for(int i=1;i<=dim;i++) bits[i]=2*bits[i-1];
-  
-  for(int i=0;i<bits[dim];i++) {
-    nodes.push_back(G.addNode());
-    for(int j=0;j<dim;j++) if(i&bits[j]) G.addEdge(nodes[i-bits[j]],nodes[i]);
-  }
-}
-
-template<class Graph>
-void addBiDirHiperCube(Graph &G,int dim,vector<typename Graph::Node> &nodes)
-{
-  GRAPH_TYPEDEF_FACTORY(Graph);
-  
-  vector<int> bits(dim+1);
-  bits[0]=1;
-  for(int i=1;i<=dim;i++) bits[i]=2*bits[i-1];
-  
-  for(int i=0;i<bits[dim];i++) {
-    nodes.push_back(G.addNode());
-    for(int j=0;j<dim;j++) if(i&bits[j]) {
-      G.addEdge(nodes[i-bits[j]],nodes[i]);
-      G.addEdge(nodes[i],nodes[i-bits[j]]);
-    }
-    
-  }
-}
-
 inline int numOfOnes(int n,int dim)
 {
   int s=0;



More information about the Lemon-commits mailing list