当前位置: 首页>>代码示例>>C++>>正文


C++ CPUTimer::getCPUTotalSecs方法代码示例

本文整理汇总了C++中CPUTimer::getCPUTotalSecs方法的典型用法代码示例。如果您正苦于以下问题:C++ CPUTimer::getCPUTotalSecs方法的具体用法?C++ CPUTimer::getCPUTotalSecs怎么用?C++ CPUTimer::getCPUTotalSecs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CPUTimer的用法示例。


在下文中一共展示了CPUTimer::getCPUTotalSecs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main( int argc, const char * argv[] )
{
  int n_itrs = MAX;
  
  #ifdef SHOW_QS
    mpz_class quoc;
  #endif  

  if( argc > 1 )
    n_itrs = atoi( argv[1] );

  #ifdef TIME
    CPUTimer timer;
    unsigned int runs = 0;
  #endif

  for(int x = -n_itrs; x < n_itrs; ++x)
    for(int y = -n_itrs; y < n_itrs; ++y)
    {
      if( y == x )
        continue;

      Quociente q( x , y ) ;

      for(int k = 1 ; k < n_itrs; ++k)
      {
        std::cout << "x[" << x << "] y[" << y << "] k[" << k << "]\n";

        #ifdef TIME
          timer.start();
        #endif

        #ifdef SHOW_QS
          quoc = q.FindFor( k );
        #else
          q.FindFor( k );
        #endif

        #ifdef TIME
          timer.stop();
          
          runs++;

          std::cout << "\tTrial time: " << timer.getCPUCurrSecs() << "s" << std::endl;
        #endif
        #ifdef SHOW_QS
          std::cout << "\tQuocient: " << quoc << std::endl;
        #endif        

       
      }      
    }

  #ifdef TIME
    std::cout << "\n\nTotal time: " << timer.getCPUTotalSecs() << "s" << std::endl;
    std::cout << "Avg. time : " << timer.getCPUTotalSecs()/runs << "s" << std::endl;
  #endif

  return 0;
}
开发者ID:IanAlbuquerque,项目名称:discrete_structures_classes,代码行数:60,代码来源:main.cpp

示例2: main

int main(){
  unsigned int n_lines, max_val, i, ret, a = 0, b = 0, c = 0; 
  bst_ret b_ret;
  char op;
  bst * h = NULL;
   
  scanf(" %u %u", &n_lines, &max_val); 
  
  /* Create the binary tree */
  b_ret = bst_create(&h, n_lines);
  if(b_ret == bst_NoMem){
    printf("ERROR: No memory to create bst tree!\n");
    printf("\t\tSize: %u\n", n_lines);
    exit(1);
  }

  /* Intiatializing time variables */
  insTime.reset();
  searchTime.reset();
  remTime.reset();
  
  /* Read the input file */
  for(i = 0; i < n_lines; i++){
    scanf(" %c %*d %[^\n]", &op, set);
	
    switch( op ){
      /* Insertion */
      case 'i':
        ret = insert(h, set);
        
        #ifdef _LOG
          if( ret  == OP_OK )
            printf("i   OK  %s\n", set);
          else if( ret == PREV_INSERTED )
            printf("i PREV  %s\n", set);
          else if( ret == BST_FULL) {
            printf("ERROR: bst if full!\n\tcould not insert %s\n", set);
            exit( 1 );
          }
        #endif

        a++;

      break;
      /* Search */
      case 'b':
        ret = search(h, set);
        
        #ifdef _LOG
          if( ret == OP_OK )
            printf("b  FND  %s\n", set);
          else
            printf("b ~FND  %s\n", set);
        #endif
        
        b++;

      break;
      /* Removal */
      case 'r':
        ret = _delete(h, set); 
        #ifdef _LOG
          if( ret == OP_OK )
            printf("r   OK  %s\n", set);
          else
            printf("r ~FND  %s\n", set);
        #endif

        c++;

      break;
      /* Wrong code */
      default:
        printf("ERROR: Wrong input at line %u!\n", i+1);
        exit(1);
    } 
  }

  if(a == 0)
    a++;
  if(b == 0)
    b++;
  if(c == 0)
    c++;

  printf("\n\nSTATISTICS\n==========\n\n");
  /* Insertion */
  printf(" Insertion Total Time: %lfs\n\tInsertion Average Time: %.12lfms\n",
         insTime.getCPUTotalSecs(), (insTime.getCPUTotalSecs() / a) * 1000 );
  /* Search */
  printf(" Search Total Time:    %lfs\n\tSearch Average Time:    %.12lfms\n",
         searchTime.getCPUTotalSecs(), (searchTime.getCPUTotalSecs() / b) * 1000 );
  /* Removal */
  printf(" Remove Total Time:    %lfs\n\tRemove Average Time:    %.12lfms\n", 
         remTime.getCPUTotalSecs(), (remTime.getCPUTotalSecs() / c) * 1000 );
  /* Total running time */
  printf("Total Running time:    %lfs\n", ( remTime.getCPUTotalSecs() +  
         searchTime.getCPUTotalSecs() + insTime.getCPUTotalSecs() ) );
 
  bst_destroy(h);
//.........这里部分代码省略.........
开发者ID:calmattoso,项目名称:EDA,代码行数:101,代码来源:bst_test.cpp

示例3: main

/**
 * Reads in the input file, performs the KP-frac linear time strategy on the 
 *   input and displays the optimal solution.
 */
int main (int argc, char * argv[]) {
    if (argc <= 1) {
        std::cout << "Please indicate the name of the input file." << std::endl;
        return -1;
    }

    CPUTimer timer;

    std::cout << "Instance, Avg Running Time (s), Number of Iterations, Value" << std::endl; 

    for (int fileIdx = 1; fileIdx < argc; fileIdx++) {
        parser(argv[fileIdx]);

        Object * temp = new Object[num_elem];

        for (int i = 0; i < num_elem; i++)
            temp[i] = objects[i];

        timer.reset();        

        int it = 0;
        while (timer.getCPUTotalSecs() < 5.0)
        {
            inserted.clear();
            timer.start();
            kpfrac_linear(objects, num_elem, W); 
            timer.stop();      
            it++;
            for(int j = 0; j < num_elem; j++)
                objects[j] = temp[j];
        }

        double media = timer.getCPUTotalSecs() / it;

        std::cout << argv[fileIdx] << "," << media << "," << it; 

        // Loop over the array of objects and display which were inserted and with
        //   what frequency.
        
        double totalValue = 0;

        #ifdef DEBUG
            std::cout << "Elem | Value | Weight | Density | Frequency" << std::endl;
        #endif

        for (int i = 0, len = inserted.size(); i < len; i++) {
            Object obj = inserted[i];

            #ifdef DEBUG
                std::cout << "Elem | Value | Weight | Density | Frequency" << std::endl;
                std::cout << obj.elem   << " " << obj.value   << " " 
                          << obj.weight << " " << obj.density << " "
                          << obj.frequency << std::endl;
            #endif

            totalValue  += obj.frequency * obj.value;
        }
        
        std::cout << std::setprecision(15) << "," << totalValue << std::endl;

        delete [] objects;
        inserted.clear();
    }

    return 0;
}
开发者ID:gbarros,项目名称:INF1721,代码行数:70,代码来源:kpfrac_linear.cpp


注:本文中的CPUTimer::getCPUTotalSecs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。