Skip to content

Commit

Permalink
bench: Fix warnings and a crash.
Browse files Browse the repository at this point in the history
* Some compilers complain about an unused variable in test mode 9.  I
  believe the purpose of this variable is to prevent the loop from being
  optimized away since mode 9 seems to be an attempt to measure memory
  bandwidth.  I suspect modern compilers are smart enough to discard the
  entire loop, but in case they aren't, rewrite the loop and add a dummy
  statement to suppress the warning.

* Instead of having a single `tre_regfree()` call at the end, which
  segfaults if `tre_regcomp()` has not been called (as is the case for
  test mode 9) or `tre_regfree()` has already been called (as is the
  case for test mode 4), make sure there is exactly one `tre_regfree()`
  call for each `tre_regcomp()` call.
  • Loading branch information
dag-erling committed Sep 13, 2024
1 parent ad55b97 commit a26cf72
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions tests/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ main(int argc, char **argv)
len = len + (max_len/steps);
free(str);
}
tre_regfree(&reobj);
break;


Expand All @@ -229,6 +230,7 @@ main(int argc, char **argv)
len = len + (max_len/steps);
free(str);
}
tre_regfree(&reobj);
break;


Expand All @@ -248,6 +250,7 @@ main(int argc, char **argv)
len = len + (max_len/steps);
free(str);
}
tre_regfree(&reobj);
break;

case 3:
Expand All @@ -268,6 +271,7 @@ main(int argc, char **argv)
len = len + (max_len/steps);
free(str);
}
tre_regfree(&reobj);
break;

case 4:
Expand Down Expand Up @@ -329,6 +333,7 @@ main(int argc, char **argv)
len = len + (max_len/steps);
free(str);
}
tre_regfree(&reobj);
break;


Expand All @@ -355,6 +360,7 @@ main(int argc, char **argv)
len = len + (max_len/steps);
free(str);
}
tre_regfree(&reobj);
break;


Expand Down Expand Up @@ -385,6 +391,7 @@ main(int argc, char **argv)
len = len + (max_len/steps);
free(str);
}
tre_regfree(&reobj);
break;


Expand Down Expand Up @@ -417,6 +424,7 @@ main(int argc, char **argv)
len = len + (max_len/steps);
free(str);
}
tre_regfree(&reobj);
break;


Expand All @@ -435,20 +443,13 @@ main(int argc, char **argv)
for (i = 0; i < samples; i++) {
c1 = clock();
for (j = 0; j < repeats; j++) {
char *s;
int l;

s = str;
l = 0;


while (*s /* TBR added * */ != '\0') {
if (*s == 'a') {
s++;
l++;
} else
unsigned long l = 0;
for (char *s = str; *s != '\0'; s++) {
if (*s != 'a')
break;
l++;
}
(void)l;
}
c2 = clock();
sample_data[i] = (double)(c2-c1)/(CLOCKS_PER_SEC*repeats);
Expand All @@ -472,7 +473,5 @@ main(int argc, char **argv)
return 1;
}

tre_regfree(&reobj);

return 0;
}

0 comments on commit a26cf72

Please sign in to comment.