char *test_binstr_performance()
{
  int i = 0;
  int found_at = 0;
  unsigned long find_count = 0;
  time_t elapsed = 0;
  time_t start = time(NULL);
  int j  = 0;

  Stats *st = Stats_create();

  while (j <= 10) {
    do {
      for(i = 0; i < 1000; i++) {
        found_at = binstr(&IN_STR, 0, &ALPHA);
        mu_assert(found_at != BSTR_ERR, "Failed to find!");
        find_count++;
      }
      elapsed = time(NULL) - start;
      Stats_sample(st, (double)find_count);
    } while(elapsed <= TEST_TIME);
    i = 0;
    found_at = 0;
    find_count = 0;
    elapsed = 0;
    start = time(NULL);
    j++;
  }

  Stats_dump(st);

  return NULL;
}
Example #2
0
int Server_create_stat(Hashmap *store, char *name)
{
  bstring b_name = bfromcstr(name);
  Stats *new_stat = Stats_create();
  check(new_stat != NULL, "Failed to create stat");
  int rc = Hashmap_set(store, b_name, new_stat);

  return rc;

error:
  if (b_name) { free(b_name); }
  return -1;
}
Example #3
0
char* test_operations() {
    int i = 0;
    Stats* st = Stats_create();
    mu_assert(st != NULL, "Failed to create stats.");

    for(i = 0; i < NUM_SAMPLES; i++) {
        Stats_sample(st, samples[i]);
    }

    Stats_dump(st);

    mu_assert(EQ(st->sumsq, expect.sumsq, 3), "sumsq not valid");
    mu_assert(EQ(st->sum, expect.sum, 3), "sum not valid");
    mu_assert(EQ(st->min, expect.min, 3), "min not valid");
    mu_assert(EQ(st->max, expect.max, 3), "max not valid");
    mu_assert(EQ(st->n, expect.n, 2), "n not valid");
    mu_assert(EQ(expect_mean, Stats_mean(st), 3), "mean not valid");
    mu_assert(EQ(expect_stddev, Stats_stddev(st), 3), "stddev not valid");

    return NULL;
}
char *test_scan_performance()
{
  int i = 0;
  int found_at = 0;
  unsigned long find_count = 0;
  time_t elapsed = 0;
  StringScanner *scan = StringScanner_create(&IN_STR);
  time_t start = time(NULL);
  int j = 0;

  Stats *st = Stats_create();

  while (j <=10) {
    do {
      for(i = 0; i < 1000; i++) {
        found_at = 0;

        do {
          found_at = StringScanner_scan(scan, &ALPHA);
          find_count++;
        } while(found_at != -1);
      }

      elapsed = time(NULL) - start;
      Stats_sample(st, (double)find_count);
    } while(elapsed <= TEST_TIME);
    i = 0;
    found_at = 0;
    find_count = 0;
    elapsed = 0;
    start = time(NULL);
    j++;
  }

  Stats_dump(st);

  StringScanner_destroy(scan);

  return NULL;
}
Example #5
0
char *test_operations() {
    int i = 0;
    Stats *st = Stats_create();
    mu_assert(st != NULL, "failed to create stats");

    for (i = 0; i < NUM_SAMPLES; i++) {
        Stats_sample(st, samples[i]);
    }
    Stats_dump(st);

    // note ble->bla is syntactic sugar for (*ble).bla
    // in this context st is a pointer while expect is not
    mu_assert(EQ(st->sumsq, expect.sumsq, 3), "sumsq invalid");
    mu_assert(EQ(st->sum, expect.sum, 3), "sum invalid");
    mu_assert(EQ(st->min, expect.min, 3), "min invalid ");
    //mu_assert(EQ(st->max, expect.max, 3), "max invalid"); not accurate enough for some reason
    mu_assert(EQ(st->n, expect.n, 3), "n invalid");
    mu_assert(EQ(Stats_mean(st), expect_mean, 3), "mean invalid");
    mu_assert(EQ(Stats_stddev(st), expect_stddev, 3), "stddev invalid");

    return NULL;
}
char *test_find_performance()
{

  srand(time(NULL));

  int i = 0;
  int found_at = 0;
  unsigned long find_count = 0;
  time_t elapsed = 0;
  time_t start = time(NULL);
  int j  = 0;

  Stats *st = Stats_create();

  while (j <=10) {
    do {
      for(i = 0; i < 1000; i++) {
        found_at = String_find(&IN_STR, &ALPHA);
        find_count++;
      }

      elapsed = time(NULL) - start;
      Stats_sample(st, (double)find_count);
    } while(elapsed <= TEST_TIME);
    i = 0;
    found_at = 0;
    find_count = 0;
    elapsed = 0;
    start = time(NULL);
    j++;
  }

  Stats_dump(st);

  return NULL;
}