如何设置排练时间 [英] how to set exct timing

查看:96
本文介绍了如何设置排练时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void wipe_status(char * drive_path,long file_num, long gap)
{
    clear_console_screen();
   int p;
   p=a/20;
   printf("\n Total files :%d\n",p);
  // printf("\n Diffence Time:%dmin",file_num);
    fprintf(stdout, "%s - %s\n\nStatus: Wiping free space in progress [Press ENTER to stop]", PROGRAM_NAME, PROGRAM_VER);
    fprintf(stdout, "\nNote: Don''t stop with CTRL+C otherwise the temporary files will not be deleted");
    fprintf(stdout, "\nInfo: %ld Mb written in %5.2f min\n", (long) ((long)file_num)*((long)DEFAULT_FILE_SIZE), (float)gap/60);
    fprintf(stdout, "\nTotal Mb:............%ld   Total Times:----------%5.2f min\n",a,a*(.00225) ); 
 
   // fprintf(stdout, "\nRemaining Time:----------%5.2f min ",((float)a*(.0005166))-(float)gap/60);
  //  fprintf(stdout, "\nRemaining Time:----------%5.2f min ",((float)a*(5.1*(10^(-3))))-(float)gap/60);
 //   if((a%20)==0)
//    {
      if(file_num<=p)
      {
                   
        fprintf(stdout, "\nProgress ............%ld Percent ",  ((100*file_num)/p));
        fprintf(stdout, "\nRemaining ...........%ld Percent ",  (100-((100*file_num)/p)));
      }
      else
      {
          p=p+1;
          fprintf(stdout, "\nProgress ............%ld Percent ",  ((100*file_num)/p));
          fprintf(stdout, "\nRemaining ...........%ld Percent ",  (100-((100*file_num)/p)));
      }
    fflush(stdout);
}
int wipe(char * drive_path, long file_size)
{
    
    FILE * f;
    int i;
    int const buf_size = 4096;
    long written;
    long file_num = 0;
    unsigned char buf[buf_size];
    unsigned int iseed;
    unsigned char filepath[256];
    int write_failed;
    time_t now_t, start_t;
    
    file_size = file_size * 1024000L;
    time(&start_t);
    wipe_status(drive_path,0L, 0L);
    
    while(1)
    {
       //sleep(1); //useless in this context
             
       written = 0;
       iseed = (unsigned int) time(NULL);
       srand (iseed);
       
       for (i=0; i<buf_size;>       {
           buf[i] = (unsigned char)( 255.0 * rand() / ( RAND_MAX + 0.0 ) );
       }  
       
       file_num++;
       write_failed = 0;  
       sprintf(filepath, "%s/%s%ld", drive_path, FILE_PREFIX, file_num);
       
       f = fopen(filepath, "wb");

       while(1){
          if (f == NULL){
             fprintf(stdout, "\nError: Unable to create file \"%s\"", filepath);
             write_failed = 1;
             break;
          }   
          
          if (stop_wiping == 1 || fwrite(buf, 1, buf_size, f) < buf_size){
             #if (DEBUG == 1)
             fprintf(stdout, "\nError: Unable to write to file \"%s\"", filepath);
             #endif
             write_failed = 1;
             break;
          }
          
          written += buf_size;
          
          if (written >= file_size){
             break;            
          }
       }
       
       if (f != NULL){
          fclose(f);
       }
       
       if (write_failed == 1){
          break;            
       }
      // wipe_status(drive_path,file_num, difftime(now_t, start_t));
      // if (file_num % 5 == 0){
          time(&now_t);
          wipe_status(drive_path,file_num, difftime(now_t, start_t));
          printf("\n Diffence Time:%5.2fmin",difftime);
     //  }
    } 
   
    delete_tmp_files(drive_path, file_num);
          
    return 0;
}



请帮助我.



Please help me.

推荐答案

printf("\n Diffence Time:%5.2fmin",difftime);
没有定义变量difftime.这应该是对该函数的调用吗?
如果它是一个全局变量,并且有一个同名的函数,这可能会使您和编译器感到困惑

我将假设"exct"是"exact"的拼写错误
以下是我用来对论文进行基准测试的部分代码.它利用了现代计算机中的高精度事件计时器(HPET).通常精确到50-100纳秒.

这段代码是Linux解决方案:
printf("\n Diffence Time:%5.2fmin",difftime);
there is no variable difftime defined. Should this be a call to the function?
If it is a global variable, and there is a function by the same name this could get confusing for you and the compiler

I am going to assume that "exct" is a misspelling of "exact"
The following is portions of code I am using for benchmarking my thesis. It makes use of the High Precision Event Timer (HPET) which is part of modern computers. This is typically accurate to around 50-100 nanoseconds.

This code is a linux solution:
#include <time.h>
#include <stdio.h>
#include <unistd.h> //for usleep()

void TimerStart(struct timespec *pSpec) {
   clock_gettime(CLOCK_REALTIME, pSpec);
}

double TimerStop(struct timespec *pSpec) {
   struct timespec t;
   clock_gettime(CLOCK_REALTIME, &t);
   return (t.tv_sec - pSpec->tv_sec) + (t.tv_nsec - pSpec->tv_nsec) * 1.0e-9;
}

//sample usage
int main() {
   struct timespec ts;
   TimerStart(&ts);
   usleep(1000000);
   printf("Time taken: %2.3f microseconds\n", TimerStop(&ts) * 1000000);
   return 0;
}



这是Windows的等效项:



And this is the windows equivalent:

#include <stdio.h>
#include <Windows.h>

void TimerStart(LARGE_INTEGER *pSpec) {
	QueryPerformanceCounter(pSpec);
}

double TimerStop(LARGE_INTEGER *pSpec) {
	LARGE_INTEGER li, liFreq;
	QueryPerformanceCounter(&li);
	QueryPerformanceFrequency(&liFreq); //If you want to optimise, do this once and save the result
	return (li.QuadPart - pSpec->QuadPart) / (double)liFreq.QuadPart;
}

//sample usage
int main() {
	LARGE_INTEGER ts;
	TimerStart(&ts);
	Sleep(1000);
	printf("Time taken: %2.3f microseconds\n", TimerStop(&ts) * 1000000);
	return 0;
}


这篇关于如何设置排练时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆