Some tools of common usage was put to bench_tool.h
authoralpar
Tue, 20 Jul 2004 09:50:11 +0000
changeset 711b6c56353832c
parent 710 891f99700ea1
child 712 6f1abe741fb6
Some tools of common usage was put to bench_tool.h
src/benchmark/Makefile.am
src/benchmark/bench_tools.h
src/benchmark/graph-bench.cc
src/benchmark/hcube.cc
     1.1 --- a/src/benchmark/Makefile.am	Tue Jul 20 09:43:12 2004 +0000
     1.2 +++ b/src/benchmark/Makefile.am	Tue Jul 20 09:50:11 2004 +0000
     1.3 @@ -2,6 +2,6 @@
     1.4  
     1.5  noinst_PROGRAMS = graph-bench hcube
     1.6  
     1.7 -graph_bench_SOURCES = graph-bench.cc
     1.8 +graph_bench_SOURCES = graph-bench.cc bench_tools.h
     1.9  
    1.10 -hcube_SOURCES = hcube.cc
    1.11 +hcube_SOURCES = hcube.cc bench_tools.h
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/benchmark/bench_tools.h	Tue Jul 20 09:50:11 2004 +0000
     2.3 @@ -0,0 +1,73 @@
     2.4 +// -*- mode:C++ -*-
     2.5 +#ifndef HUGO_BENCH_TEST_H
     2.6 +#define HUGO_BENCH_TEST_H
     2.7 +
     2.8 +#include<vector>
     2.9 +
    2.10 +///An experimental typedef factory
    2.11 +#define GRAPH_TYPEDEF_FACTORY(Graph) \
    2.12 +   typedef typename Graph::   Node      Node;\
    2.13 +   typedef typename Graph::   NodeIt    NodeIn;\
    2.14 +   typedef typename Graph::   Edge      Edge;\
    2.15 +   typedef typename Graph::   EdgeIt    EdgeIt;\
    2.16 +   typedef typename Graph:: InEdgeIt  InEdgeIt;\
    2.17 +   typedef typename Graph::OutEdgeIt OutEdgeIt;
    2.18 +
    2.19 +#define GRAPH_TYPEDEF_FACTORY_NOTYPENAME(Graph) \
    2.20 +   typedef Graph::   Node      Node;\
    2.21 +   typedef Graph::   NodeIt    NodeIn;\
    2.22 +   typedef Graph::   Edge      Edge;\
    2.23 +   typedef Graph::   EdgeIt    EdgeIt;\
    2.24 +   typedef Graph:: InEdgeIt  InEdgeIt;\
    2.25 +   typedef Graph::OutEdgeIt OutEdgeIt;
    2.26 + 
    2.27 +
    2.28 +///A primitive primtest
    2.29 +bool isPrim(int n)
    2.30 +{
    2.31 +  if(n%2) {
    2.32 +    for(int k=3;n/k>=k;k+=2)
    2.33 +      if(!(n%k)) return false;
    2.34 +    return true;
    2.35 +  }
    2.36 +  return false;
    2.37 +}
    2.38 +
    2.39 +///Finds the smallest prime not less then \c n.
    2.40 +int nextPrim(int n)
    2.41 +{
    2.42 +  for(n+=!(n%2);!isPrim(n);n+=2) ;
    2.43 +  return n;
    2.44 +}
    2.45 +
    2.46 +
    2.47 +/// Class to generate consecutive primes
    2.48 +class Primes 
    2.49 +{
    2.50 +  std::vector<int> primes;
    2.51 +  int n;
    2.52 +  
    2.53 +  bool isPrime(int m) 
    2.54 +  {
    2.55 +    for(int i=0;m<primes[i]*primes[i];i++) if(!(m%primes[i])) return false;
    2.56 +    return true;
    2.57 +  }
    2.58 +public:
    2.59 +  Primes() : n(1) {}
    2.60 +  
    2.61 +  int operator() ()
    2.62 +    {
    2.63 +      if(primes.size()==0) {
    2.64 +	primes.push_back(2);
    2.65 +	return 2;
    2.66 +      }
    2.67 +      else {
    2.68 +	do n+=2; while(!isPrime(n));
    2.69 +	primes.push_back(n);
    2.70 +	return n;
    2.71 +      }
    2.72 +    }
    2.73 +};
    2.74 +
    2.75 +
    2.76 +#endif
     3.1 --- a/src/benchmark/graph-bench.cc	Tue Jul 20 09:43:12 2004 +0000
     3.2 +++ b/src/benchmark/graph-bench.cc	Tue Jul 20 09:50:11 2004 +0000
     3.3 @@ -2,39 +2,11 @@
     3.4  #include<hugo/list_graph.h>
     3.5  #include<hugo/time_measure.h>
     3.6  #include<iostream>
     3.7 -#include<sage_graph.h>
     3.8 -#include<vector>
     3.9 +
    3.10 +#include"bench_tools.h"
    3.11  
    3.12  using namespace hugo;
    3.13  
    3.14 -///An experimental typedef factory
    3.15 -#define GRAPH_TYPEDEF_FACTORY(Graph) \
    3.16 -   typedef typename Graph::   Node      Node;\
    3.17 -   typedef typename Graph::   NodeIt    NodeIn;\
    3.18 -   typedef typename Graph::   Edge      Edge;\
    3.19 -   typedef typename Graph::   EdgeIt    EdgeIt;\
    3.20 -   typedef typename Graph:: InEdgeIt  InEdgeIt;\
    3.21 -   typedef typename Graph::OutEdgeIt OutEdgeIt;
    3.22 - 
    3.23 -
    3.24 -///A primitive primtest
    3.25 -bool isPrim(int n)
    3.26 -{
    3.27 -  if(n%2) {
    3.28 -    for(int k=3;n/k>=k;k+=2)
    3.29 -      if(!(n%k)) return false;
    3.30 -    return true;
    3.31 -  }
    3.32 -  return false;
    3.33 -}
    3.34 -
    3.35 -///Finds the smallest prime not less then \c n.
    3.36 -int nextPrim(int n)
    3.37 -{
    3.38 -  for(n+=!(n%2);!isPrim(n);n+=2) ;
    3.39 -  return n;
    3.40 -}
    3.41 -
    3.42  ///Makes a full graph by adding and deleting a lot of edges;
    3.43  
    3.44  ///\param n Number of nodes.
     4.1 --- a/src/benchmark/hcube.cc	Tue Jul 20 09:43:12 2004 +0000
     4.2 +++ b/src/benchmark/hcube.cc	Tue Jul 20 09:50:11 2004 +0000
     4.3 @@ -6,56 +6,12 @@
     4.4  #include<hugo/dijkstra.h>
     4.5  #include<hugo/time_measure.h>
     4.6  #include<iostream>
     4.7 -#include<../work/jacint/max_flow.h>
     4.8 +//#include<../work/jacint/max_flow.h>
     4.9 +#include"bench_tools.h"
    4.10  
    4.11  using namespace std;
    4.12  using namespace hugo;
    4.13  
    4.14 -///An experimental typedef factory
    4.15 -#define GRAPH_TYPEDEF_FACTORY(Graph) \
    4.16 -   typedef typename Graph::   Node      Node;\
    4.17 -   typedef typename Graph::   NodeIt    NodeIn;\
    4.18 -   typedef typename Graph::   Edge      Edge;\
    4.19 -   typedef typename Graph::   EdgeIt    EdgeIt;\
    4.20 -   typedef typename Graph:: InEdgeIt  InEdgeIt;\
    4.21 -   typedef typename Graph::OutEdgeIt OutEdgeIt;
    4.22 -
    4.23 -#define GRAPH_TYPEDEF_FACTORY_NOTYPENAME(Graph) \
    4.24 -   typedef Graph::   Node      Node;\
    4.25 -   typedef Graph::   NodeIt    NodeIn;\
    4.26 -   typedef Graph::   Edge      Edge;\
    4.27 -   typedef Graph::   EdgeIt    EdgeIt;\
    4.28 -   typedef Graph:: InEdgeIt  InEdgeIt;\
    4.29 -   typedef Graph::OutEdgeIt OutEdgeIt;
    4.30 -
    4.31 -
    4.32 -class Primes 
    4.33 -{
    4.34 -  vector<int> primes;
    4.35 -  int n;
    4.36 -  
    4.37 -  bool isPrime(int m) 
    4.38 -  {
    4.39 -    for(int i=0;m<primes[i]*primes[i];i++) if(!(m%primes[i])) return false;
    4.40 -    return true;
    4.41 -  }
    4.42 -public:
    4.43 -  Primes() : n(1) {}
    4.44 -  
    4.45 -  int operator() ()
    4.46 -    {
    4.47 -      if(primes.size()==0) {
    4.48 -	primes.push_back(2);
    4.49 -	return 2;
    4.50 -      }
    4.51 -      else {
    4.52 -	do n+=2; while(!isPrime(n));
    4.53 -	primes.push_back(n);
    4.54 -	return n;
    4.55 -      }
    4.56 -    }
    4.57 -};
    4.58 -
    4.59  template<class Graph>
    4.60  void addHiperCube(Graph &G,int dim,vector<typename Graph::Node> &nodes)
    4.61  {