×

rarvesa_vga

消耗积分:2 | 格式:rar | 大小:106 | 2010-02-25

吴湛

分享资料个

rarvesa_vga.rar

/* testsum.c: Program to time assembler vs. C implementations of
 *       array summation code.
 * Copyright (C) 1991 by Nicholas Wilt.  All rights reserved.
 */

#include "testfpu.h"

int
main(int argc, char *argv[])
{
  struct time beg, end;
  double x;
  int y;
  double ret;
  long i;
  int j;
  long dead, slow, fast;
  long numreps;
  float *summe;
  int arrsize;

  if (argc != 3) {
    fprintf(stderr, "Usage: testsum #iters #elems\n");
    fprintf(stderr, "\t#iters = number of iterations of test\n");
    fprintf(stderr, "\t#elems = number of elements in arrays\n");
    exit(1);
  }
  else {
    char *sc;
    numreps = strtol(argv[1], &sc, 10);
    arrsize = atoi(argv[2]);
  }

  summe = (float *) malloc(arrsize * sizeof(float));
  for (i = 0; i < arrsize; i++)
    summe[i] = (double) rand() / (RAND_MAX / 2);

  printf("Calculating dead time...");
  gettime(&beg);
  for (i = 0; i < numreps; i++)
    ;
  gettime(&end);
  dead = diff_time(&beg, &end);
  printf("%.2f seconds\n", (float) dead/100);

  printf("Timing inline summation...");
  gettime(&beg);
  for (i = 0; i < numreps; i++) {
    double ret = 0;
    int j;
    for (j = 0; j < arrsize; j++)
      ret += summe[j];
  }
  gettime(&end);
  slow = diff_time(&beg, &end);
  printf("%.2f seconds\n", (float) slow/100);

  printf("Timing sumarray()...");
  gettime(&beg);
  for (i = 0; i < numreps; i++) {
    ret = sumarray(summe, arrsize);
  }
  gettime(&end);
  fast = diff_time(&beg, &end);
  printf("%.2f seconds\n", (float) fast/100);
  printf("sumarray() %d%% faster than inline code to do summation\n", percent_diff(dead, fast, slow));
  free(summe);
  return 0;
}


声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !