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); 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; } while(elapsed <= TEST_TIME); debug("SCAN COUNT: %lu, END TIME: %d, OPS: %f", find_count, (int)elapsed, (double)find_count / elapsed); StringScanner_destroy(scan); return NULL; }
char *test_find_and_scan() { StringScanner *scan = StringScanner_create(&IN_STR); mu_assert(scan != NULL, "Failed to make the scanner."); int find_i = String_find(&IN_STR, &ALPHA); mu_assert(find_i > 0, "Failed to find 'ALPHA' in test string."); int scan_i = StringScanner_scan(scan, &ALPHA); mu_assert(scan_i > 0, "Failed to find 'ALPHA' with scan."); mu_assert(scan_i == find_i, "find and scan don't match"); scan_i = StringScanner_scan(scan, &ALPHA); mu_assert(scan_i > find_i, "should find another ALPHA after the first"); scan_i = StringScanner_scan(scan, &ALPHA); mu_assert(scan_i > find_i, "should find another ALPHA after the first"); mu_assert(StringScanner_scan(scan, &ALPHA) == -1, "shouldn't find it"); StringScanner_destroy(scan); 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; }
char *test_find_and_scan() { StringScanner *scan = StringScanner_create(&IN_STR); mu_assert(scan != NULL, "Failed to make the scanner."); int find_i = String_find(&IN_STR, &ALPHA); mu_assert(find_i > 0, "Failed to find 'ALPHA' in test string."); int scan_i = StringScanner_scan(scan, &ALPHA); mu_assert(scan_i > 0, "Failed to find 'ALPHA' with scan."); mu_assert(scan_i == find_i, "Find and Scan don't match."); scan_i = StringScanner_scan(scan, &ALPHA); mu_assert(scan_i > find_i, "Should find a second 'ALPHA' after the first."); scan_i = StringScanner_scan(scan, &ALPHA); mu_assert(scan_i > find_i, "Should find third 'ALPHA' after the first."); mu_assert(StringScanner_scan(scan, &ALPHA) == -1, "Shouldn't find a fourth 'ALPHA' after the third."); StringScanner_destroy(scan); return NULL; }