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


C++ cputime函数代码示例

本文整理汇总了C++中cputime函数的典型用法代码示例。如果您正苦于以下问题:C++ cputime函数的具体用法?C++ cputime怎么用?C++ cputime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: main

main()
{
  int i;
  double temp1, temp2, rn;
  double temp_mult = TIMING_TRIAL_SIZE/1.0e6;
  
  temp1 = cputime();

  for(i=0; i<TIMING_TRIAL_SIZE; i++)
    rn = drand48();
  
  temp2 = cputime();
  

  if(temp2-temp1 < 1.0e-15 )
  {
    printf("Timing Information not available/not accurate enough.\n\t...Exiting\n");
    exit(1);
  }
  
  /* The next line is just used to ensure that the optimization does not remove the call to the RNG. Nothing is really printed.             */
  fprintf(stderr,"Last random number generated\n", rn);
  
  printf("\nUser + System time Information (Note: MRS = Million Random Numbers Per Second)\n");
  printf("\tDRAND48:\t Time = %7.3f seconds => %8.4f MRS\n", 
	 temp2-temp1, temp_mult/(temp2-temp1));
  putchar('\n');
  
}
开发者ID:AthrunArthur,项目名称:ffssca2,代码行数:29,代码来源:drand.c

示例2: main

int
main (int argc, char *argv[])
{
  gmp_randstate_t rs;
  mpz_t x, y, z;
  unsigned long int m, n, i, niter, t0, ti;
  double t, f, ops_per_sec;
  int decimals;

  if (argc != 3)
    {
      fprintf (stderr, "usage: %s m n\n", argv[0]);
      fprintf (stderr, "  where m is number of dividend bits\n");
      fprintf (stderr, "    and n is number of divisor bits\n");
      return -1;
    }

  m = atoi (argv[1]);
  n = atoi (argv[2]);

  gmp_randinit_default (rs);

  mpz_init (x);
  mpz_init (y);
  mpz_init (z);
  mpz_urandomb (x, rs, m);
  mpz_urandomb (y, rs, n);

  printf ("Calibrating CPU speed...");  fflush (stdout);
  TIME (t, mpz_tdiv_q (z, x, y));
  printf ("done\n");

  niter = 1 + (unsigned long) (1e4 / t);
  printf ("Dividing an %lu-bit number by an %lu-bit number %lu times...",
	  m, n, niter);
  fflush (stdout);
  t0 = cputime ();
  for (i = niter; i > 0; i--)
    {
      mpz_tdiv_q (z, x, y);
    }
  ti = cputime () - t0;
  printf ("done!\n");

  ops_per_sec = 1000.0 * niter / ti;
  f = 100.0;
  for (decimals = 0;; decimals++)
    {
      if (ops_per_sec > f)
	break;
      f = f * 0.1;
    }

  printf ("RESULT: %.*f operations per second\n", decimals, ops_per_sec);
  return 0;
}
开发者ID:faterer,项目名称:groof_off,代码行数:56,代码来源:divide.c

示例3: main

main()
{
	int i, n = 1000000;
	float cpu_used, a = 0.0, b = 1.0;

	cpu_used = cputime();
	for (i = 0; i < n; ++i)  a += b;
	cpu_used = cputime() - cpu_used;
	printf("a = %f  cpu time = %f\n", a, cpu_used);
}
开发者ID:gwowen,项目名称:seismicunix,代码行数:10,代码来源:cputime.c

示例4: nemo_main

nemo_main()
{
  int n=getiparam("n");
  int iter=getiparam("iter");
  int m=getiparam("m");
  int seed = init_xrandom(getparam("seed"));
  int i,j,k,l;
  real *x, sum;
  real t0,t1,t2;

  init_timers(100);
  stamp_timers(0);

  x = (real *) allocate(n*sizeof(real));

  for (i=0; i<n; i++)         /* init the whole array */
    x[i] = xrandom(0.0,1.0);
  for (i=0; i<m; i++)         /* cache it in again ? */
    x[i] = xrandom(0.0,1.0);

  sum = 0.0;
  t0 = cputime();
  stamp_timers(1);
  if (m==0) {                         /* do it in one sweep, the N^2 algorithm */
    stamp_timers(2);
    for (l=0; l<iter;  l++)
      for (j=0; j<n; j++)
	for (i=0; i<n; i++)
	  sum += FUN(x[i],x[j]);
    stamp_timers(3);
  } else {                            /* N/M times a small M*M patch that may be in cache */
    stamp_timers(2);
    for (l=0; l<iter; l++)
      for (k=0; k<n-m; k++)
	for (j=k; j<k+m; j++)
	  for (i=k; i<k+m; i++)
	    sum += FUN(x[i],x[j]);
    stamp_timers(3);
  }
  stamp_timers(4);
  t1 = cputime();
  if (m)
    printf("%d %d %d sum=%lg Mops=%lg\n",
	 n,iter,m,sum,iter*m*m*n/(t1-t0)/60.0/1e6);
  else
    printf("%d %d %d sum=%lg Mops=%lg\n",
	 n,iter,m,sum,iter*n*n/(t1-t0)/60.0/1e6);
  stamp_timers(5);
  printf("%Ld %Ld %Ld %Ld %Ld\n",
	 diff_timers(0,1),
	 diff_timers(1,2),
	 diff_timers(2,3),
	 diff_timers(3,4),
	 diff_timers(4,5));
}
开发者ID:Milkyway-at-home,项目名称:nemo,代码行数:55,代码来源:square.c

示例5: main

int
main (int argc, char *argv[])
{
  unsigned long N = atoi (argv[1]), M;
  mp_prec_t p;
  mpfr_t i, j;
  char *lo;
  mp_exp_t exp_lo;
  int st, st0;

  fprintf (stderr, "Using GMP %s and MPFR %s\n", gmp_version, mpfr_version);
  st = cputime ();

  mpfr_init (i);
  mpfr_init (j);

  M = N;

  do
    {
      M += 10;
      mpfr_set_prec (i, 32);
      mpfr_set_d (i, LOG2_10, GMP_RNDU);
      mpfr_mul_ui (i, i, M, GMP_RNDU);
      mpfr_add_ui (i, i, 3, GMP_RNDU);
      p = mpfr_get_ui (i, GMP_RNDU);
      fprintf (stderr, "Setting precision to %lu\n", p);

      mpfr_set_prec (j, 2);
      mpfr_set_prec (i, p);
      mpfr_set_ui (j, 1, GMP_RNDN);
      mpfr_exp (i, j, GMP_RNDN); /* i = exp(1) */
      mpfr_set_prec (j, p);
      mpfr_const_pi (j, GMP_RNDN);
      mpfr_div (i, i, j, GMP_RNDN);
      mpfr_sqrt (i, i, GMP_RNDN);

      st0 = cputime ();
      lo = mpfr_get_str (NULL, &exp_lo, 10, M, i, GMP_RNDN);
      st0 = cputime () - st0;
    }
  while (can_round (lo, N, M) == 0);

  lo[N] = '\0';
  printf ("%s\n", lo);

  mpfr_clear (i);
  mpfr_clear (j);

  fprintf (stderr, "Cputime: %dms (output %dms)\n", cputime () - st, st0);
  return 0;
}
开发者ID:jpouderoux,项目名称:core,代码行数:52,代码来源:c02.c

示例6: main

int main() {
	cputime("started up");
	int i;
	for (i = 0; i < NELEM; ++i)
		data[i] = rand();
	cputime("filled with %d random values", NELEM);
	sleep(SLEEP);
	cputime("did nothing for %d seconds", SLEEP);
	memcpy(data2, data, sizeof data);
	cputime("copied %lu bytes with memcpy", (unsigned long) sizeof data);
	memcpy(data2, data, sizeof data);
	cputime("copied %lu bytes with memmove", (unsigned long) sizeof data);
}
开发者ID:tbfe-de,项目名称:plc2-ccpp-psi,代码行数:13,代码来源:filldata.c

示例7: patch

void
patch(void)
{
	vlong c, vexit;
	Prog *p, *q;
	Sym *s;
	int a;

	if(debug['v'])
		Bprint(&bso, "%5.2f patch\n", cputime());
	Bflush(&bso);
	mkfwd();
	s = lookup("exit", 0);
	vexit = s->value;
	for(p = firstp; p != P; p = p->link) {
		a = p->as;
		if(a == ATEXT)
			curtext = p;
		if((a == AJAL || a == AJMP || a == ARET) &&
		   p->to.type != D_BRANCH && p->to.sym != S) {
			s = p->to.sym;
			if(s->type != STEXT) {
				diag("undefined: %s\n%P", s->name, p);
				s->type = STEXT;
				s->value = vexit;
			}
			p->to.offset = s->value;
			p->to.type = D_BRANCH;
		}
		if(p->to.type != D_BRANCH)
			continue;
		c = p->to.offset;
		for(q = firstp; q != P;) {
			if(q->forwd != P)
			if(c >= q->forwd->pc) {
				q = q->forwd;
				continue;
			}
			if(c == q->pc)
				break;
			q = q->link;
		}
		if(q == P) {
			diag("branch out of range %lld\n%P", c, p);
			p->to.type = D_NONE;
		}
		p->cond = q;
	}

	for(p = firstp; p != P; p = p->link) {
		if(p->as == ATEXT)
			curtext = p;
		if(p->cond != P) {
			p->cond = brloop(p->cond);
			if(p->cond != P)
			if(p->to.type == D_BRANCH)
				p->to.offset = p->cond->pc;
		}
	}
}
开发者ID:bbarker,项目名称:plan9,代码行数:60,代码来源:pass.c

示例8: cputime

  void TimeMeter::Start()
  {
    if (!stoped_)
      return;

    stoped_ = false;
    begin_ = cputime();
  }
开发者ID:dedok,项目名称:nkit,代码行数:8,代码来源:tools.cpp

示例9: search_fopen

static void
search_fopen(char *db, char **s)
{
	FILE *fp;
#ifdef DEBUG
        long t0;
#endif
	       
	/* can only read stdin once */
	if (f_stdin) { 
		fp = stdin;
		if (*(s+1) != NULL) {
			warnx("read database from stdin, use only `%s' as pattern", *s);
			*(s+1) = NULL;
		}
	} 
	else if ((fp = fopen(path_fcodes, "r")) == NULL)
		err(1,  "`%s'", path_fcodes);

	/* count only chars or lines */
	if (f_statistic) {
		statistic(fp, path_fcodes);
		(void)fclose(fp);
		return;
	}

	/* foreach search string ... */
	while(*s != NULL) {
#ifdef DEBUG
		t0 = cputime();
#endif
		if (!f_stdin &&
		    fseek(fp, (long)0, SEEK_SET) == -1)
			err(1, "fseek to begin of ``%s''\n", path_fcodes);

		if (f_icase)
			fastfind_icase(fp, *s, path_fcodes);
		else
			fastfind(fp, *s, path_fcodes);
#ifdef DEBUG
		warnx("fastfind %ld ms", cputime () - t0);
#endif
		s++;
	} 
	(void)fclose(fp);
} 
开发者ID:kusumi,项目名称:DragonFlyBSD,代码行数:46,代码来源:locate.c

示例10: loop_for

static int loop_for(int id, double exec_time)
{
	double last_loop = 0, loop_start;
	int tmp = 0;

	double start = cputime();
	double now = cputime();

	while (now + last_loop < start + exec_time) {
		loop_start = now;
		tmp += loop_once();
		now = cputime();
		last_loop = now - loop_start;
	}

	return tmp;
}
开发者ID:zs673,项目名称:litmus_mrsp,代码行数:17,代码来源:preempt.c

示例11: startguprof

/*
 * The start and stop routines need not be here since we turn off profiling
 * before calling them.  They are here for convenience.
 */
void
startguprof(struct gmonparam *gp)
{

	gp->profrate = tick_freq;
	cputime_bias = 0;
	cputime();
}
开发者ID:dcui,项目名称:FreeBSD-9.3_kernel,代码行数:12,代码来源:prof_machdep.c

示例12: sphreport

void sphreport(stream ostr, smxptr sm, string options)
{
  bodyptr *bptr = sm->kd->bptr;
  int i, nupd, nlev[MAXLEV+1], *rprof = sm->rprof;
  real rbsum, rbmin, rbmax, flev[MAXLEV+1], flev4, xi[NRPROF-1];

  nupd = 0;
  for (i = 0; i <= MAXLEV; i++)
    nlev[i] = 0;
  rbsum = 0.0;
  for (i = 0; i < sm->kd->ngas; i++) {
    if (Update(bptr[i])) {
      nupd++;
      nlev[NewLevel(bptr[i])]++;
      rbsum += Smooth(bptr[i]);
      rbmin = (nupd == 1 ? Smooth(bptr[i]) : MIN(rbmin, Smooth(bptr[i])));
      rbmax = (nupd == 1 ? Smooth(bptr[i]) : MAX(rbmin, Smooth(bptr[i])));
    }
  }
  flev4 = 0.0;
  for (i = 0; i <= MAXLEV; i++) {
    flev[i] = 100.0 * ((real) nlev[i]) / ((real) nupd);
    if (i >= 4)
      flev4 += flev[i];
  }
  fprintf(ostr, "\n%9s %9s %9s %9s %29s %9s\n",
	  "log hmin", "log havg", "log hmax", "freqavg",
	  "timestep level distribution", "CPUsph"); 
  fprintf(ostr,
	  "%9.4f %9.4f %9.4f %9.2f %5.1f %5.1f %5.1f %5.1f %5.1f %9.3f\n",
	  rlog10(rbmin), rlog10(rbsum / nupd), rlog10(rbmax),
	  sm->freqsum / nupd, flev[0], flev[1], flev[2], flev[3], flev4,
	  cputime() - sm->cpustart);
  if (scanopt(options, "corrfunc")) {
    for (i = 0; i <= NRPROF - 2; i++)
      xi[i] = -1 + rpow(8.0, i/2.0) * (rprof[i] - rprof[i+1]) /
	((1 - rsqrt(0.125)) * rprof[0]);
    fprintf(ostr, "\n     ");
    for (i = NRPROF - 2; i >= 0; i--)
      fprintf(ostr, "   xi%d", i);
    fprintf(ostr, "\n     ");
    for (i = NRPROF - 2; i >= 0; i--)
      fprintf(ostr, "%6.2f", xi[i]);
    fprintf(ostr, "\n");
  }	
  if (scanopt(options, "levelhist")) {
    fprintf(ostr, "\n     ");
    for (i = 0; i <= MAXLEV; i++)
      if (nlev[i] != 0)
	fprintf(ostr, i<10 ? "  lev%d" : " lev%d", i);
    fprintf(ostr, "\n     ");
    for (i = 0; i <= MAXLEV; i++)
      if (nlev[i] != 0)
	fprintf(ostr, "%6d", nlev[i]);
    fprintf(ostr, "\n");
  }	
  fflush(ostr);
}
开发者ID:jasminegrosso,项目名称:zeno,代码行数:58,代码来源:smooth.c

示例13: doprof1

void
doprof1(void)
{
#if 0
	Sym *s;
	int32 n;
	Prog *p, *q;

	if(debug['v'])
		Bprint(&bso, "%5.2f profile 1\n", cputime());
	Bflush(&bso);
	s = lookup("__mcount", 0);
	n = 1;
	for(cursym = textp; cursym != nil; cursym = cursym->next) {
		p = cursym->text;
		q = prg();
		q->line = p->line;
		q->link = datap;
		datap = q;
		q->as = ADATA;
		q->from.type = D_EXTERN;
		q->from.offset = n*4;
		q->from.sym = s;
		q->from.scale = 4;
		q->to = p->from;
		q->to.type = D_CONST;

		q = prg();
		q->line = p->line;
		q->pc = p->pc;
		q->link = p->link;
		p->link = q;
		p = q;
		p->as = AADDL;
		p->from.type = D_CONST;
		p->from.offset = 1;
		p->to.type = D_EXTERN;
		p->to.sym = s;
		p->to.offset = n*4 + 4;

		n += 2;
	}
	q = prg();
	q->line = 0;
	q->link = datap;
	datap = q;

	q->as = ADATA;
	q->from.type = D_EXTERN;
	q->from.sym = s;
	q->from.scale = 4;
	q->to.type = D_CONST;
	q->to.offset = n;

	s->type = SBSS;
	s->size = n*4;
#endif
}
开发者ID:Ahmah2009,项目名称:golang,代码行数:58,代码来源:prof.c

示例14: do_busywork

int do_busywork(int wss, double budget)
{
    double last_loop = 0;
    double loop_start;
    int tmp = 0;

    double start = cputime();
    double now = cputime();

    while (now + last_loop < start + (budget / 1000)) {
        loop_start = now;
        tmp += dirty_kb(wss);
        now = cputime();
        last_loop = now - loop_start;
    }

    return tmp;
}
开发者ID:felipeqc,项目名称:experiments,代码行数:18,代码来源:busywork.c

示例15: main_prompt

main_prompt()
	{
	ITEM c;
	char mess[MAXMESS],mess1[MAXMESS];
	double start;
	for (;;) {
		printf("|- ");
		if((c=ccl_ttyread())==(ITEM)I_TERM) break;
		else if(c==(ITEM)I_ERROR) continue;
		ccl_swrite(mess,c);
		start=cputime();
		c_interp(c);
		sprintf(mess1,"%s - Time taken %.2lfs",mess,
			fabs(cputime()-start));
		g_message(1l,mess1);
		i_delete(c);
	}
}
开发者ID:MaxChaza,项目名称:M2BBS,代码行数:18,代码来源:command.c


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