#define ADD_SUB_TEST 20000000
#define MUL_TEST 10000000
-#define DIV_TEST 10000000
+#define DIV_TEST 1048573 // at 1048573, fixed point numbers wrap around to zero
using namespace etl;
/* === C L A S S E S ======================================================= */
MyTimer.reset();
for(i=0;i<ADD_SUB_TEST;i++)
{
- a+=a;
- a+=b;
- a-=c;
- a-=a;
-
- a+=a;
- a+=b;
- a-=c;
- a-=a;
-
- a+=a;
- a+=b;
- a-=c;
- a-=a;
-
- a+=a;
- a+=b;
- a-=c;
- a-=a;
-
- a+=a;
- a+=b;
- a-=c;
- a-=a;
-
- a+=a;
- a+=b;
- a-=c;
- a-=a;
-
- a+=a;
- a+=b;
- a-=c;
- a-=a;
-
+ a+=a; a-=b; a-=c; a+=a;
+ a+=a; a-=b; a-=c; a+=a;
+ a+=a; a-=b; a-=c; a+=a;
+ a+=a; a-=b; a-=c; a+=a;
+ a+=a; a-=b; a-=c; a+=a;
+ a+=a; a-=b; a-=c; a+=a;
+ a+=a; a-=b; a-=c; a+=a;
}
-
+ fprintf(stderr, "[%1d]...", int(int(a)/1e9)+5); // so the compiler doesn't optimize everything out
return MyTimer();
}
double mul_test(void)
{
value_type a,b,c,d;
- a=value_type(0.25);
+ a=value_type(2.25);
b=value_type(2);
c=value_type(4.5);
- const value_type half(static_cast<value_type>(0.5));
+ d=value_type(1);
+ const value_type one_and_a_half(static_cast<value_type>(1.5));
int i;
etl::clock MyTimer;
MyTimer.reset();
- for(i=0;i<MUL_TEST;i++)
+ for(i=1;i<MUL_TEST;i++)
{
- d*=a;d*=b;d*=c;d*=3;d*=i;
- b*=c;b*=d;b*=d;b*=3;
- c*=d;c*=half;c*=a;c*=b;c*=3;
- a*=c;a*=b;a*=3;
-
- d*=a;d*=b;d*=c;d*=3;d*=i;
- b*=c;b*=d;b*=d;b*=3;
- c*=d;c*=half;c*=a;c*=b;c*=3;
- a*=c;a*=b;a*=3;
-
- d*=a;d*=b;d*=c;d*=3;d*=i;
- b*=c;b*=d;b*=d;b*=3;
- c*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b*=d;b*=3; c*=d;c*=one_and_a_half;c*=a;c*=b;c*=3; a*=c;a*=b;a*=3;
}
+
+ fprintf(stderr, "[%1d]...", int(int(a)/1e9)+5); // so the compiler doesn't optimize everything out
return MyTimer();
}
{
value_type a(30);
value_type b(40);
- int i;
+ value_type acc(0);
+ int i, j;
etl::clock MyTimer;
MyTimer.reset();
- for(i=1;i<DIV_TEST;i++)
- {
- a=3+i;
- b=40+i;
- b/=a;
- a/=(i%20)+1;
-
- a=3+i;
- b=40+i;
- b/=a;
- a/=(i%20)+1;
-
- a=3+i;
- b=40+i;
- b/=a;
- a/=(i%20)+1;
-
- a=3+i;
- b=40+i;
- b/=a;
- a/=(i%20)+1;
-
- a=3+i;
- b=40+i;
- b/=a;
- a/=(i%20)+1;
-
- a=3+i;
- b=40+i;
- b/=a;
- a/=(i%20)+1;
-
- }
-
-
+ for(j=0;j<10;j++)
+ for(i=1;i<DIV_TEST;i++)
+ {
+ a=3+i; b=40+i; b/=a; a/=(i%20)+1; acc+= a;
+ a=3+i; b=40+i; b/=a; a/=(i%20)+1; acc+= a;
+ a=3+i; b=40+i; b/=a; a/=(i%20)+1; acc+= a;
+ a=3+i; b=40+i; b/=a; a/=(i%20)+1; acc+= a;
+ a=3+i; b=40+i; b/=a; a/=(i%20)+1; acc+= a;
+ a=3+i; b=40+i; b/=a; a/=(i%20)+1; acc+= a;
+ }
+
+ fprintf(stderr, "[%1d]...", int(int(a)/1e9)+5); // so the compiler doesn't optimize everything out
return MyTimer();
}
};
d-=(double)a;
fprintf(stderr,"fixed: ( 1043 / 27 + 10.42 ) / 6 * PI --- Difference: %f\n",d);
if(d<0.0)d=-d;
+#ifdef ROUND_TO_NEAREST_INTEGER
if( d>0.0005)
+#else
+ if( d>0.0025)
+#endif
{
fprintf(stderr,"fixed: Failed test on line %d in "__FILE__".\n",__LINE__);
ret++;
int main()
{
- fprintf(stderr, "\n***\n");
- fprintf(stderr, "*** tests in fixed.cpp fail - see http://wiki.synfig.com/Source:ETL_make_check for an explanation ***\n");
- fprintf(stderr, "***\n\n");
- sleep(5);
-
int error=0;
error+=basic_test();
{
double flt,fix,inte;
- fprintf(stderr,"Addition/subtraction test...");
+ fprintf(stderr,"\nAddition/subtraction test...\n");
- fprintf(stderr,"calculating float...");
+ fprintf(stderr," calculating float.....");
flt=float_test.add_sub_test();
- fprintf(stderr,"float time: %fsec\n",flt);
+ fprintf(stderr," float time: %f sec\n",flt);
- fprintf(stderr,"calculating fixed...");
+ fprintf(stderr," calculating fixed.....");
fix=fixed_test.add_sub_test();
- fprintf(stderr,"fixed time: %fsec\n",fix);
+ fprintf(stderr," fixed time: %f sec\n",fix);
- fprintf(stderr,"calculating integer...");
+ fprintf(stderr," calculating integer...");
inte=int_test.add_sub_test();
- fprintf(stderr,"integer time: %fsec\n",inte);
+ fprintf(stderr," integer time: %f sec\n",inte);
if(flt>fix)
fprintf(stderr,"Fixed point wins by %f seconds! (%f%% faster)\n",flt-fix,flt/fix*100.0f-100.0f);
{
double flt,fix,inte;
- fprintf(stderr,"Product test...");
- fprintf(stderr,"calculating float...");
+ fprintf(stderr,"\nProduct test...\n");
+ fprintf(stderr," calculating float.....");
flt=float_test.mul_test();
- fprintf(stderr,"float time: %fsec\n",flt);
- fprintf(stderr,"calculating fixed...");
+ fprintf(stderr," float time: %f sec\n",flt);
+ fprintf(stderr," calculating fixed.....");
fix=fixed_test.mul_test();
- fprintf(stderr,"fixed time: %fsec\n",fix);
- fprintf(stderr,"calculating integer...");
+ fprintf(stderr," fixed time: %f sec\n",fix);
+ fprintf(stderr," calculating integer...");
inte=int_test.mul_test();
- fprintf(stderr,"integer time: %fsec\n",inte);
+ fprintf(stderr," integer time: %f sec\n",inte);
if(flt>fix)
fprintf(stderr,"Fixed point wins by %f seconds! (%f%% faster)\n",flt-fix,flt/fix*100.0f-100.0f);
else
fprintf(stderr,"Floating point wins by %f seconds! (%f%% faster)\n",fix-flt,fix/flt*100.0f-100.0f);
-
}
{
double flt,fix,inte;
- fprintf(stderr,"Division test...");
- fprintf(stderr,"calculating float...");
+ fprintf(stderr,"\nDivision test...\n");
+ fprintf(stderr," calculating float.....");
flt=float_test.div_test();
- fprintf(stderr,"float time: %fsec\n",flt);
- fprintf(stderr,"calculating fixed...");
+ fprintf(stderr," float time: %f sec\n",flt);
+ fprintf(stderr," calculating fixed.....");
fix=fixed_test.div_test();
- fprintf(stderr,"fixed time: %fsec\n",fix);
- fprintf(stderr,"calculating integer...");
+ fprintf(stderr," fixed time: %f sec\n",fix);
+ fprintf(stderr," calculating integer...");
inte=int_test.div_test();
- fprintf(stderr,"integer time: %fsec\n",inte);
+ fprintf(stderr," integer time: %f sec\n",inte);
if(flt>fix)
fprintf(stderr,"Fixed point wins by %f seconds! (%f%% faster)\n",flt-fix,flt/fix*100.0f-100.0f);
else
fprintf(stderr,"Floating point wins by %f seconds! (%f%% faster)\n",fix-flt,fix/flt*100.0f-100.0f);
-
+ fprintf(stderr,"\n");
}
return error;