Ejemplo n.º 1
0
void
test_no_branching(void)
{
  int n;

  for (n = 16; n < 1024*1024*64; n *= 2) {
    int i;
    int std_sum, nob_sum;
    pTimer tmr; ptimer_init(&tmr, CLOCK_PROCESS_CPUTIME_ID);

    printf("n:%d ", n);

    ptimer_tic(&tmr);
    std_sum = 0;
    for (i = 0; i < n; i++) {
      std_sum ^= int_min2(i, n - i);
    }
    ptimer_toc(&tmr);
    printf("std:"); ptimer_print_sec_usec9(tmr);

    ptimer_tic(&tmr);
    nob_sum = 0;
    for (i = 0; i < n; i++) {
      nob_sum ^= int_min_no_branching(i, n - i);
    }
    ptimer_toc(&tmr);
    printf(" nob:"); ptimer_print_sec_usec9(tmr);

    if (std_sum != nob_sum) {
      printf(" NOT EQUAL!");
    } else {
      printf(" sum:%d", std_sum);
    }

    endline();
  }
}
Ejemplo n.º 2
0
int vcs_status(std::vector<VCS_STATUS_t>& status_list_return,
               const char * dir,
               VCS_t vcs)
{
    int ret = -1;
    pTimer tmr; ptimer_tic(&tmr);

    if (vcs == VCS_undefined_) {
        // TODO: use SemNet pPatts to figure out \c vcs from contents of current directory (\c Dir) and matchers for these.
        vcs = VCS_GIT;
    }
    pid_t child = -1;           // child process
    int out, err;
    const char * envp[] = { nullptr };
    const char * cmd = nullptr;
    const char * op = "status";
    const char * flag = "-S";
    switch (vcs) {
    case VCS_CVS: cmd = "cvs"; break;
    case VCS_SVN: cmd = "svn"; break;
    case VCS_GIT: cmd = "git"; flag = "-s"; break;
    case VCS_BZR: cmd = "bzr"; break;
    case VCS_HG:  cmd = "hg";  break;
    case VCS_DARCS: cmd = "darcs"; op = "show"; break;
    default: break;
    }
    const char * argv[] = { cmd, op, flag, nullptr };
    ret = auto_required_spawn(find_executable_by_name(cmd).c_str(), dir,
                              const_cast<char* const*>(argv), const_cast<char* const*>(envp),
                              &child, nullptr, &out, &err);

    int status;
    waitpid(child, &status, 0); // wait for process to terminate
    std::cout << "status:" << status << std::endl;

    ptimer_toc(&tmr);
    ptimer_print_sec_usec9(tmr); endline();

    int rc, c;
    // read out
    std::cout << "out:" << std::endl;
    while ((rc = read(out, &c, 1)) > 0) { std::cout << char(c); }

    // read err
    std::cerr << "err:" << std::endl;
    while ((rc = read(err, &c, 1)) > 0) { std::cout << char(c); }

    return ret;
}
Ejemplo n.º 3
0
void
test_kdTree_rbal(kdTree * tree, int show)
{
  pTimer tmr; ptimer_init(&tmr, CLOCK_PROCESS_CPUTIME_ID);

  ptimer_tic(&tmr);
  kdTree_rbal(tree);
  ptimer_toc(&tmr);

  printf("- Balance: "); ptimer_print_sec_usec9(tmr); printf("[s]");

  if (show_bars) {
    int x = (int)rint(ptimer_get_sec(&tmr) * fac);
    mputchar(stdout, x, '#');
  }

  endline();
}
Ejemplo n.º 4
0
void
test_kdTree_find_shape(kdTree * tree,
                       vis_t ** grid, size_t m, size_t n, int show)
{
  size_t k;
  pTimer tmr; ptimer_init(&tmr, CLOCK_PROCESS_CPUTIME_ID);

  ptimer_tic(&tmr);

  kdTree_reset_fbs(tree);

  size_t hitnum = 0;
  for (k = 0; k < m * n; k++) {
    const vis_t * elm = grid[k];

    if (show) {
      printf("finding ");
      vis_fprint(stdout, elm);
      printf(" nr:%zd/%zd...", k, m * n);
    }

    int hit = kdTree_find_shape(tree, elm);
    if (hit) { hitnum++; }

    if (show) {
      printf("%s", hit ? "HIT: " : "MISS");
      endline();
    }
  }

  ptimer_toc(&tmr);

  printf("- Find: "); ptimer_print_sec_usec9(tmr); printf("[s]");
  printf(" (%zd) %s ", hitnum, (hitnum == m * n) ? "SUCCESS" : "FAILURE");

  if (show_bars) {
    int x = (int)rint(ptimer_get_sec(&tmr) * fac);
    mputchar(stdout, x, '#');
  }

  endline();
}
Ejemplo n.º 5
0
void
test_kdTree_ins_shape(kdTree * tree,
                      vis_t ** grid, size_t m, size_t n, int show)
{
  size_t k;
  pTimer tmr; ptimer_init(&tmr, CLOCK_PROCESS_CPUTIME_ID);

  ptimer_tic(&tmr);

  for (k = 0; k < m * n; k++) {
    vis_t * elm = grid[k];

    if (show) {
      printf("inserting ");
      vis_fprint(stdout, elm);
      printf(" nr:%zd/%zd...", k, m * n);
    }

    kdTree_ins_shape(tree, elm);

    if (show) {
      kdTree_fprint(stdout, tree, TRUE);
      putsep(stdout);
    }

    if (show) {
      endline();
    }
  }

  ptimer_toc(&tmr);

  printf("- Insertion: "); ptimer_print_sec_usec9(tmr); printf("[s]");

  if (show_bars) {
    int x = (int)rint(ptimer_get_sec(&tmr) * fac);
    putchar(' ');
    mputchar(stdout, x, '#');
  }

  endline();
}
Ejemplo n.º 6
0
void
test_kdTree_rm_shape(kdTree * tree,
                     vis_t ** grid, size_t m, size_t n, int show)
{
  pTimer tmr; ptimer_init(&tmr, CLOCK_PROCESS_CPUTIME_ID);

  ptimer_tic(&tmr);

  size_t k, rmnum = 0;
  for (k = 0; k < m * n; k++) {
    vis_t * elm = grid[k];

    if (show) {
      printf("removing ");
      vis_fprint(stdout, elm);
      printf(" nr:%zd/%zd...", k, m * n);
    }

    uint ok = kdTree_rm_shape(tree, elm);

    if (ok) {
      rmnum++;
    }

    if (show) {
      printf("%s\n", ok ? "HIT" : "MISS");
    }
  }

  ptimer_toc(&tmr);

  printf("- Remove: "); ptimer_print_sec_usec9(tmr); printf("[s]");
  printf(" (%zd) %s ", rmnum, (rmnum == m * n) ? "SUCCESS" : "FAILURE");

  if (show_bars) {
    int x = (int)rint(ptimer_get_sec(&tmr) * fac);
    mputchar(stdout, x, '#');
  }

  endline();
}
Ejemplo n.º 7
0
void
test_kdTree_major(float step, float dim,
                  size_t m,
                  size_t n,
                  int random,
                  int shuffle, int show, int end_show)
{
  size_t k, l;

  /* we need a timer for benchmarkings */
  pTimer tmr; ptimer_init(&tmr, CLOCK_PROCESS_CPUTIME_ID);

  vis_t ** grid = ptrarrayvis_newGrid(step, dim, m, n, random);

  /* shuffle the boxes around */
  if (shuffle) {
    ptimer_tic(&tmr);
    ptrarray_shuffle((void**)grid, m * n);
    ptimer_toc(&tmr);
    printf("- Shuffle: "); ptimer_print_sec_usec9(tmr);  printf("[s]"); endline();
  }

  /* create the tree */
  kdTree * tree;
  tree = kdTree_new();

  /* standard search  */
  ptimer_tic(&tmr);
  for (k = 0; k < m * n; k++) {
    for (l = 0; l < n * n; l++) {
      if (grid[k] == grid[l]) {
        break;
      }
    }
  }
  ptimer_toc(&tmr);

  printf("- Scan: "); ptimer_print_sec_usec9(tmr); printf("[s]"); endline();

  /* insert them into tree */
  test_kdTree_ins_shape(tree, grid, m, n, show);

  /* search them in the tree */
  test_kdTree_find_shape(tree, grid, m, n, show);

  /* print it */
  printf("- Printing: "); kdTree_fprint(stdout, tree, end_show);

  /* recursively balance tree */
  test_kdTree_rbal(tree, show);

  /* search them again in the balanced tree */
  test_kdTree_find_shape(tree, grid, m, n, show);

  /* print it */
  printf("- Printing: "); kdTree_fprint(stdout, tree, end_show);

  /* remove them from the tree */
  test_kdTree_rm_shape(tree, grid, m, n, show);

  /* print it */
  printf("- Printing: "); kdTree_fprint(stdout, tree, end_show);

  /* remove boxes */
  ptimer_tic(&tmr);
  ptrarrayvis_clrGrid(grid, m, n);
  ptimer_toc(&tmr);
  printf("- Remove (grid): "); ptimer_print_sec_usec9(tmr);  printf("[s]"); endline();

  ptimer_tic(&tmr);
  kdTree_delete(tree, FALSE);
  ptimer_toc(&tmr);
  printf("- kdTree delete: "); ptimer_print_sec_usec9(tmr);  printf("[s]"); endline();

  endline();
}