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


C++ Benchmark::getSecs方法代码示例

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


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

示例1: read

double read(const char * filename, std::streampos size, int n_files, int blocksize)
{
    if (debug) printf("\n%d files: ", n_files);
    FILE * files[n_files];

    // Open files, and set pos
    for (int i = 0; i<n_files; ++i)
    {
	files[i] = fopen ( filename, "rb" );

        long int pos = (size/n_files)*i;
	fseek ( files[i], pos, SEEK_SET );
	
        if (debug) printf("%lld, ", (unsigned long long) pos);
    }
    if (debug) printf("\n");
    
    // Read size/n_files bytes from all files
    Benchmark t; t.start();
    
    uint32_t * buffer = (uint32_t *) malloc(blocksize);
    
    // Every slice is 250' / number of files big
    for (uint32_t i=0; i<(size/n_files); i+=blocksize)
    {
        // should be unrolled?
        for (int j = 0; j<n_files; ++j)
	  {
	    //	  size_t res =  
	    fread(buffer, 1, blocksize, files[j] );
	    
	    /*
	  for (uint32_t z=0; z<blocksize/sizeof(int); ++z)
	  {
	  if (buffer[z] == 0)
	  printf("Read first byte\n");
	  if (buffer[z] == 249999999)
	  printf("Read last byte\n");
	  // fprintf(stderr, "Reading %d \n", buffer[z]);
	  }
	    //*/
	  }
    }
    t.stop();
    
    // Close all files
    free(buffer);
    for (int i = 0; i<n_files; ++i)
      fclose(files[i]);
    
    return t.getSecs();
}
开发者ID:trondkla,项目名称:TDT4225,代码行数:52,代码来源:test.cpp

示例2: random_read

double random_read(const char * filename, std::streampos size, int blocksize)
{
    FILE * file;

    file = fopen ( filename, "rb" );

    if (debug) printf("\n");
    
    // Read size/n_files bytes from all files
    Benchmark t; t.start();
    
    uint32_t * buffer = (uint32_t *) malloc(blocksize);
    
    // Every slice is 250' / number of files big
    //    for (uint32_t i=0; i<size; i+=blocksize)
    for (uint32_t i=0; i<=249999999; ++i)
    {
      long int pos = rand() % size;
      fseek ( file, pos, SEEK_SET );
      //      size_t res = 
      fread(buffer, 1, blocksize, file );
      
      /*
	for (uint32_t z=0; z<blocksize/sizeof(int); ++z)
	{
	if (buffer[z] == 0)
	printf("Read first byte\n");
	if (buffer[z] == 249999999)
	printf("Read last byte\n");
	      // fprintf(stderr, "Reading %d \n", buffer[z]);
	      }
      //*/
      
    }
    t.stop();
    
    // Close all files
    free(buffer);
    fclose(file);
    
    return t.getSecs();
}
开发者ID:trondkla,项目名称:TDT4225,代码行数:42,代码来源:test.cpp


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