From 6da812e4ee6d6620d3a77ca1ac47a32161ba5aab Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sun, 3 Jul 2011 19:34:10 +0100 Subject: eval: make timing optional in test program Signed-off-by: Mans Rullgard --- libavutil/eval.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'libavutil/eval.c') diff --git a/libavutil/eval.c b/libavutil/eval.c index 4bba343bec..8ce687df19 100644 --- a/libavutil/eval.c +++ b/libavutil/eval.c @@ -533,6 +533,8 @@ int av_expr_parse_and_eval(double *d, const char *s, #ifdef TEST #undef printf +#include + static double const_values[] = { M_PI, M_E, @@ -545,7 +547,7 @@ static const char *const_names[] = { 0 }; -int main(void) +int main(int argc, char **argv) { int i; double d; @@ -617,13 +619,16 @@ int main(void) NULL, NULL, NULL, NULL, NULL, 0, NULL); printf("%f == 0.931322575\n", d); - for (i=0; i<1050; i++) { - START_TIMER + if (argc > 1 && !strcmp(argv[1], "-t")) { + for (i = 0; i < 1050; i++) { + START_TIMER; av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, NULL); - STOP_TIMER("av_expr_parse_and_eval") + STOP_TIMER("av_expr_parse_and_eval"); + } } + return 0; } #endif -- cgit v1.2.3 From 94350ab986dfce1c93fa720baf28b548c60a9879 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Mon, 4 Jul 2011 12:26:59 +0100 Subject: eval: clear Parser instances before using This prevents random values from the stack being used as "variables" in expressions. Signed-off-by: Mans Rullgard --- libavutil/eval.c | 4 ++-- tests/ref/fate/eval | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'libavutil/eval.c') diff --git a/libavutil/eval.c b/libavutil/eval.c index 8ce687df19..4d55f42664 100644 --- a/libavutil/eval.c +++ b/libavutil/eval.c @@ -461,7 +461,7 @@ int av_expr_parse(AVExpr **expr, const char *s, const char * const *func2_names, double (* const *funcs2)(void *, double, double), int log_offset, void *log_ctx) { - Parser p; + Parser p = { 0 }; AVExpr *e = NULL; char *w = av_malloc(strlen(s) + 1); char *wp = w; @@ -506,7 +506,7 @@ end: double av_expr_eval(AVExpr *e, const double *const_values, void *opaque) { - Parser p; + Parser p = { 0 }; p.const_values = const_values; p.opaque = opaque; diff --git a/tests/ref/fate/eval b/tests/ref/fate/eval index bcc1a505b0..fb7a925b77 100644 --- a/tests/ref/fate/eval +++ b/tests/ref/fate/eval @@ -92,7 +92,7 @@ Evaluating 'st(1, 123); ld(1)' 'st(1, 123); ld(1)' -> 123.000000 Evaluating 'st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)' -'st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)' -> 5073.000000 +'st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)' -> 4950.000000 Evaluating 'st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)' 'st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)' -> 144.000000 -- cgit v1.2.3