summaryrefslogtreecommitdiff
path: root/test/test_regset.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2020-04-20 20:34:10 +0200
committerJörg Frings-Fürst <debian@jff.email>2020-04-20 20:34:10 +0200
commitf3d6e46ce3762b6f51a166119d3982fd3715507a (patch)
tree0935fb6da7f1d9728b42ddf08395a0e977e1c228 /test/test_regset.c
parent043fff5b6f2461aeccb1c62cb771826cfe301832 (diff)
parent73c6133c32cddae59813cbadf655cb50a3a7356a (diff)
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'test/test_regset.c')
-rw-r--r--test/test_regset.c46
1 files changed, 20 insertions, 26 deletions
diff --git a/test/test_regset.c b/test/test_regset.c
index 497fbd6..c8442a1 100644
--- a/test/test_regset.c
+++ b/test/test_regset.c
@@ -66,19 +66,16 @@ make_regset(int line_no, int n, char* pat[], OnigRegSet** rset, int error_no)
return 0;
}
-#ifndef _WIN32
-
static double
-get_sec(struct timespec* ts, struct timespec* te)
+get_sec(clock_t start, clock_t end)
{
double t;
- t = (te->tv_sec - ts->tv_sec) +
- (double )(te->tv_nsec - ts->tv_nsec) / 1000000000.0;
+ t = (double )(end - start) / CLOCKS_PER_SEC;
return t;
}
-/* clock_gettime() doesn't exist in Windows */
+/* use clock(), because clock_gettime() doesn't exist in Windows and old Unix. */
static int
time_test(int repeat, int n, char* ps[], char* s, char* end, double* rt_set, double* rt_reg)
@@ -87,14 +84,13 @@ time_test(int repeat, int n, char* ps[], char* s, char* end, double* rt_set, dou
int i;
int match_pos;
OnigRegSet* set;
- struct timespec ts1, ts2;
+ clock_t ts1, ts2;
double t_set, t_reg;
r = make_regset(0, n, ps, &set, 0);
if (r != 0) return r;
- clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts1);
-
+ ts1 = clock();
for (i = 0; i < repeat; i++) {
r = onig_regset_search(set, (UChar* )s, (UChar* )end, (UChar* )s, (UChar* )end,
ONIG_REGSET_POSITION_LEAD, ONIG_OPTION_NONE, &match_pos);
@@ -104,12 +100,10 @@ time_test(int repeat, int n, char* ps[], char* s, char* end, double* rt_set, dou
}
}
- clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts2);
- t_set = get_sec(&ts1, &ts2);
-
-
- clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts1);
+ ts2 = clock();
+ t_set = get_sec(ts1, ts2);
+ ts1 = clock();
for (i = 0; i < repeat; i++) {
r = onig_regset_search(set, (UChar* )s, (UChar* )end, (UChar* )s, (UChar* )end,
ONIG_REGSET_REGEX_LEAD, ONIG_OPTION_NONE, &match_pos);
@@ -119,16 +113,15 @@ time_test(int repeat, int n, char* ps[], char* s, char* end, double* rt_set, dou
}
}
- clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts2);
- onig_regset_free(set);
+ ts2 = clock();
+ t_reg = get_sec(ts1, ts2);
- t_reg = get_sec(&ts1, &ts2);
+ onig_regset_free(set);
*rt_set = t_set;
*rt_reg = t_reg;
return 0;
}
-#endif
static void
fisher_yates_shuffle(int n, char* ps[], char* cps[])
@@ -147,7 +140,6 @@ fisher_yates_shuffle(int n, char* ps[], char* cps[])
}
}
-#ifndef _WIN32
static void
time_compare(int n, char* ps[], char* s, char* end)
{
@@ -176,7 +168,6 @@ time_compare(int n, char* ps[], char* s, char* end)
fprintf(stdout, "POS lead: %6.2lfmsec. REG lead: %6.2lfmsec.\n",
total_set * 1000.0, total_reg * 1000.0);
}
-#endif
static OnigRegSetLead XX_LEAD = ONIG_REGSET_POSITION_LEAD;
@@ -391,11 +382,15 @@ static char* p7[] = {
"0+", "1+", "2+", "3+", "4+", "5+", "6+", "7+", "8+", "9+",
};
+static char* p8[] = {"a", ".*"};
+
extern int
main(int argc, char* argv[])
{
- int r;
+#ifndef _WIN32
int file_exist;
+#endif
+ int r;
char *s, *end;
OnigEncoding use_encs[1];
@@ -412,6 +407,7 @@ main(int argc, char* argv[])
N(p2, " XXXX AAA 1223 012345678bbb");
X2(p2, "0123456789", 9, 10);
X2(p7, "abcde 555 qwert", 6, 9);
+ X2(p8, "", 0, 0);
XX_LEAD = ONIG_REGSET_REGEX_LEAD;
@@ -432,22 +428,20 @@ main(int argc, char* argv[])
fprintf(stdout, "Ignore %s\n", TEXT_PATH);
file_exist = 0;
}
-#else
- file_exist = 0;
-#endif
if (file_exist != 0) {
X2(p2, s, 10, 22);
X2(p3, s, 496079, 496088);
X2(p4, s, 1294, 1315);
}
+#endif
fprintf(stdout,
"\nRESULT SUCC: %4d, FAIL: %d, ERROR: %d (by Oniguruma %s)\n",
nsucc, nfail, nerror, onig_version());
- if (file_exist != 0) {
#ifndef _WIN32
+ if (file_exist != 0) {
fprintf(stdout, "\n");
time_compare(ASIZE(p2), p2, s, end);
time_compare(ASIZE(p3), p3, s, end);
@@ -455,9 +449,9 @@ main(int argc, char* argv[])
time_compare(ASIZE(p5), p5, s, end);
time_compare(ASIZE(p6), p6, s, end);
fprintf(stdout, "\n");
-#endif
free(s);
}
+#endif
onig_end();