comparison eval.c @ 2436:86d14aebd527 libavcodec

simplify benchmark
author michael
date Mon, 17 Jan 2005 18:25:32 +0000
parents 24aa9209e8b0
children ef2149182f1c
comparison
equal deleted inserted replaced
2435:c89ac0e70c66 2436:86d14aebd527
139 return NAN; 139 return NAN;
140 } 140 }
141 141
142 return d; 142 return d;
143 } 143 }
144 144
145 static double evalPow(Parser *p){ 145 static double evalPow(Parser *p){
146 if(p->s[0]=='+') p->s++; 146 int sign= (*p->s == '+') - (*p->s == '-');
147 147 p->s += sign&1;
148 if(p->s[0]=='-'){ 148 return (sign|1) * evalPrimary(p);
149 p->s++;
150 return -evalPrimary(p);
151 }else
152 return evalPrimary(p);
153 } 149 }
154 150
155 static double evalFactor(Parser *p){ 151 static double evalFactor(Parser *p){
156 double ret= evalPow(p); 152 double ret= evalPow(p);
157 while(p->s[0]=='^'){ 153 while(p->s[0]=='^'){
169 } 165 }
170 return ret; 166 return ret;
171 } 167 }
172 168
173 static double evalExpression(Parser *p){ 169 static double evalExpression(Parser *p){
174 double ret; 170 double ret= 0;
175 171
176 if(p->stack_index <= 0) //protect against stack overflows 172 if(p->stack_index <= 0) //protect against stack overflows
177 return NAN; 173 return NAN;
178 p->stack_index--; 174 p->stack_index--;
179 175
180 ret= evalTerm(p); 176 do{
181 while(p->s[0]=='+' || p->s[0]=='-'){ 177 ret += evalTerm(p);
182 if(*p->s++ == '+') ret+= evalTerm(p); 178 }while(*p->s == '+' || *p->s == '-');
183 else ret-= evalTerm(p);
184 }
185 179
186 p->stack_index++; 180 p->stack_index++;
187 181
188 return ret; 182 return ret;
189 } 183 }
218 "PI", 212 "PI",
219 "E", 213 "E",
220 0 214 0
221 }; 215 };
222 main(){ 216 main(){
217 int i;
223 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)); 218 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));
219
220 for(i=0; i<1050; i++){
221 START_TIMER
222 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);
223 STOP_TIMER("ff_eval")
224 }
224 } 225 }
225 #endif 226 #endif