コード例 #1
0
ファイル: tests.c プロジェクト: MITDelian/6.172
double longrunning_rotation() {
  // We're going to be doing a bunch of rotations; we probably shouldn't
  // let the user see all the verbose output.
  test_verbose = false;

  // There's probably some great reason why this exact size was chosen for
  // the test bit array; however, if there is, it's been lost to
  // history.
  // const size_t bit_sz = 10000 * 1024 * 8 + 471;
  const size_t bit_sz = 12 * 1024 * 8 + 471;
  testutil_newrand(bit_sz, 0);

  const clockmark_t start_time = ktiming_getmark();
  testutil_rotate(0, bit_sz, -bit_sz / 4);
  testutil_rotate(0, bit_sz, bit_sz / 4);
  testutil_rotate(0, bit_sz, bit_sz / 2);
  const clockmark_t end_time = ktiming_getmark();

  // Arguably, we should set test_verbose back to whatever it was before
  // we started.  However, since we're never going to be running more than
  // one performance test at a time (or performance tests at the same time
  // as functional tests), we can just let it be.

  return ktiming_diff_usec(&start_time, &end_time) / 1000000000.0;
}
コード例 #2
0
/* A sample long-running set of flip count operations. */                     
double longrunning_flipcount(void) {
  test_verbose = false;
  size_t bit_sz = 128 * 1024 * 1024 * 8 + 531;                                
  testutil_newrand(bit_sz, 0);                                                
  clockmark_t time1 = ktiming_getmark();
  for (int i = 0; i < 20; i++)
    bitarray_count_flips(test_ba, 0, bit_sz);
  clockmark_t time2 = ktiming_getmark();                                      
  return ktiming_diff_usec(&time1, &time2) / 1000000000.0;                    
}
コード例 #3
0
/* A sample long-running set of rotation operations. */
double longrunning_rotation(void) {
  test_verbose = false;
  size_t bit_sz = 12 * 1024 * 8 + 471;
  testutil_newrand(bit_sz, 0);
  clockmark_t time1 = ktiming_getmark();
  testutil_rotate(0, bit_sz, (ssize_t) -bit_sz / 4);
  testutil_rotate(0, bit_sz, bit_sz / 4);
  testutil_rotate(0, bit_sz, bit_sz / 2);
  clockmark_t time2 = ktiming_getmark();
  
  return ktiming_diff_usec(&time1, &time2) / 1000000000.0;
}
コード例 #4
0
ファイル: testbed.c プロジェクト: jeffdshen/homework1
int main(int argc, char** argv) {
  int optchar = 0;
  int show_usec = 0;
  int should_print = 0;
  int use_zero_matrix = 0;

  // Always use the same seed, so that our tests are repeatable.
  unsigned int randomSeed = 1;

  matrix* A;
  matrix* B;
  matrix* C;

  const int kMatrixSize = 1000;


  // Parse command line arguments
  while ((optchar = getopt(argc, argv, "upz")) != -1) {
    switch (optchar) {
      case 'u':
        show_usec = 1;
        break;
      case 'p':
        should_print = 1;
        break;
      case 'z':
        use_zero_matrix = 1;
        break;
      default:
        printf("Ignoring unrecognized option: %c\n", optchar);
        continue;
    }
  }

  // This is a trick to make the memory bug leads to a wrong output.
  int size = sizeof(int) * 4;
  int* temp[20];

  for (int i = 0; i < 20; i++) {
    temp[i] = (int*)malloc(size);
    memset(temp[i], 1, size);
  }
  for (int i = 0; i < 20; i++) {
    free(temp[i]);
  }

  fprintf(stderr, "Setup\n");

  A = make_matrix(kMatrixSize, kMatrixSize);
  B = make_matrix(kMatrixSize, kMatrixSize);
  C = make_matrix(kMatrixSize, kMatrixSize);

  if (use_zero_matrix) {
    for (int i = 0; i < A->rows; i++) {
      for (int j = 0; j < A->cols; j++) {
        A->values[i][j] = 0;
      }
    }
    for (int i = 0; i < B->rows; i++) {
      for (int j = 0; j < B->cols; j++) {
        B->values[i][j] = 0;
      }
    }
  } else {
    for (int i = 0; i < A->rows; i++) {
      for (int j = 0; j < A->cols; j++) {
        A->values[i][j] = rand_r(&randomSeed) % 10;
      }
    }
    for (int i = 0; i < B->rows; i++) {
      for (int j = 0; j < B->cols; j++) {
        B->values[i][j] = rand_r(&randomSeed) % 10;
      }
    }
  }

  if (should_print) {
    printf("Matrix A: \n");
    print_matrix(A);

    printf("Matrix B: \n");
    print_matrix(B);
  }

  fprintf(stderr, "Running matrix_multiply_run()...\n");

  clockmark_t time1 = ktiming_getmark();
  matrix_multiply_run(A, B, C);
  clockmark_t time2 = ktiming_getmark();

  if (should_print) {
    printf("---- RESULTS ----\n");
    printf("Result: \n");
    print_matrix(C);
    printf("---- END RESULTS ----\n");
  }

  if (show_usec) {
    uint64_t elapsed = ktiming_diff_usec(&time1, &time2);
    printf("Elapsed execution time: %"PRIu64"usec\n", elapsed);
  } else {
    float elapsedf = ktiming_diff_sec(&time1, &time2);
    printf("Elapsed execution time: %f sec\n", elapsedf);
  }

  // free matrices after use
  free_matrix(A);
  free_matrix(B);
  free_matrix(C);

  return 0;
}