summaryrefslogtreecommitdiff
path: root/libavcodec/eval.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2005-01-17 18:25:32 +0000
committerMichael Niedermayer <michaelni@gmx.at>2005-01-17 18:25:32 +0000
commit80a49958532b598dfc95d985dc84fae91d2ae293 (patch)
tree93940286895c649e0bae53755013468fb6a87345 /libavcodec/eval.c
parentfdb86eb10d53b73f61bc86c280fa5f8f50233bf1 (diff)
simplify
benchmark Originally committed as revision 3844 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/eval.c')
-rw-r--r--libavcodec/eval.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/libavcodec/eval.c b/libavcodec/eval.c
index 4e1e8a3a34..3307815817 100644
--- a/libavcodec/eval.c
+++ b/libavcodec/eval.c
@@ -141,15 +141,11 @@ static double evalPrimary(Parser *p){
return d;
}
-
+
static double evalPow(Parser *p){
- if(p->s[0]=='+') p->s++;
-
- if(p->s[0]=='-'){
- p->s++;
- return -evalPrimary(p);
- }else
- return evalPrimary(p);
+ int sign= (*p->s == '+') - (*p->s == '-');
+ p->s += sign&1;
+ return (sign|1) * evalPrimary(p);
}
static double evalFactor(Parser *p){
@@ -171,17 +167,15 @@ static double evalTerm(Parser *p){
}
static double evalExpression(Parser *p){
- double ret;
+ double ret= 0;
if(p->stack_index <= 0) //protect against stack overflows
return NAN;
p->stack_index--;
- ret= evalTerm(p);
- while(p->s[0]=='+' || p->s[0]=='-'){
- if(*p->s++ == '+') ret+= evalTerm(p);
- else ret-= evalTerm(p);
- }
+ do{
+ ret += evalTerm(p);
+ }while(*p->s == '+' || *p->s == '-');
p->stack_index++;
@@ -220,6 +214,13 @@ static const char *const_names[]={
0
};
main(){
+ int i;
printf("%f == 12.7\n", ff_eval("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL));
+
+ for(i=0; i<1050; i++){
+ START_TIMER
+ ff_eval("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL);
+ STOP_TIMER("ff_eval")
+ }
}
#endif