1 /*! ========================================================================
2 ** Extended Template and Library Test Suite
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
18 ** === N O T E S ===========================================================
20 ** ========================================================================= */
22 /* === H E A D E R S ======================================================= */
25 #include <ETL/hermite>
27 #include <ETL/fastangle>
29 #include <ETL/surface>
30 #include <ETL/gaussian>
31 #include <ETL/calculus>
34 /* === M A C R O S ========================================================= */
37 //using namespace std;
39 #define HERMITE_TEST_ITERATIONS (100000)
41 /* === C L A S S E S ======================================================= */
43 /* === P R O C E D U R E S ================================================= */
45 template <class Angle>
46 void angle_cos_speed_test(void)
51 for(tmp=-1;tmp<1;tmp+=0.000002f)
53 a=(typename Angle::cos)(tmp);
54 b=(typename Angle::cos)(tmp);
55 c=(typename Angle::cos)(tmp);
56 d=(typename Angle::cos)(tmp);
57 tmp2=((typename Angle::cos)(a)).get();
58 tmp2=((typename Angle::cos)(b)).get();
59 tmp2=((typename Angle::cos)(c)).get();
60 tmp2=((typename Angle::cos)(d)).get();
63 template <class Angle>
64 void angle_sin_speed_test(void)
69 for(tmp=-1.0;tmp<1.0;tmp+=0.000002f)
71 a=(typename Angle::sin)(tmp);
72 b=(typename Angle::sin)(tmp);
73 c=(typename Angle::sin)(tmp);
74 d=(typename Angle::sin)(tmp);
75 tmp2=((typename Angle::sin)(a)).get();
76 tmp2=((typename Angle::sin)(b)).get();
77 tmp2=((typename Angle::sin)(c)).get();
78 tmp2=((typename Angle::sin)(d)).get();
81 template <class Angle>
82 void angle_tan_speed_test(void)
87 for(tmp=-1;tmp<1;tmp+=0.000002f)
89 a=(typename Angle::tan)(tmp);
90 b=(typename Angle::tan)(tmp);
91 c=(typename Angle::tan)(tmp);
92 d=(typename Angle::tan)(tmp);
93 tmp2=((typename Angle::tan)(a)).get();
94 tmp2=((typename Angle::tan)(b)).get();
95 tmp2=((typename Angle::tan)(c)).get();
96 tmp2=((typename Angle::tan)(d)).get();
99 template <class Angle, class mytan>
100 void angle_atan2_speed_test(void)
105 for(y=-10;y<10;y+=0.05f)
106 for(x=-10;x<10;x+=0.05f)
123 int fastangle_speed_test(void)
132 fastangle_atan2_time,
139 angle_cos_speed_test<angle>();
140 angle_cos_time=MyTimer();
141 printf("angle: Cosine test: %f seconds\n",angle_cos_time);
144 angle_cos_speed_test<fastangle>();
145 fastangle_cos_time=MyTimer();
146 printf("fastangle: Cosine test: %f seconds\n",fastangle_cos_time);
147 printf("fastangle is %.02f%% faster\n",(angle_cos_time/fastangle_cos_time)*100.0-100.0);
150 angle_sin_speed_test<angle>();
151 angle_sin_time=MyTimer();
152 printf("angle: Sine test: %f seconds\n",angle_sin_time);
155 angle_sin_speed_test<fastangle>();
156 fastangle_sin_time=MyTimer();
157 printf("fastangle: Sine test: %f seconds\n",fastangle_sin_time);
158 printf("fastangle is %.02f%% faster\n",(angle_sin_time/fastangle_sin_time)*100.0-100.0);
161 angle_tan_speed_test<angle>();
162 angle_tan_time=MyTimer();
163 printf("angle: Tangent test: %f seconds\n",angle_tan_time);
166 angle_tan_speed_test<fastangle>();
167 fastangle_tan_time=MyTimer();
168 printf("fastangle: Tangent test: %f seconds\n",fastangle_tan_time);
169 printf("fastangle is %.02f%% faster\n",(angle_tan_time/fastangle_tan_time)*100.0-100.0);
172 angle_atan2_speed_test<angle,angle::tan>();
173 angle_atan2_time=MyTimer();
174 printf("angle: arcTangent2 test: %f seconds\n",angle_atan2_time);
177 angle_atan2_speed_test<fastangle,fastangle::tan>();
178 fastangle_atan2_time=MyTimer();
179 printf("fastangle: arcTangent2 test: %f seconds\n",fastangle_atan2_time);
180 printf("fastangle is %.02f%% faster\n",(angle_atan2_time/fastangle_atan2_time)*100.0-100.0);
185 int surface_and_gaussian_blur_test()
192 surface<float> my_surface(1000,1000);
195 gaussian_blur(my_surface.begin(),my_surface.end(),30,30);
197 printf("surface_and_gaussian_blur_test<float>: %f seconds\n",endtime);
201 surface<double> my_surface(1000,1000);
204 gaussian_blur(my_surface.begin(),my_surface.end(),30,30);
206 printf("surface_and_gaussian_blur_test<double>: %f seconds\n",endtime);
210 surface<fixed> my_surface(1000,1000);
213 gaussian_blur(my_surface.begin(),my_surface.end(),30,30);
215 printf("surface_and_gaussian_blur_test<fixed>: %f seconds\n",endtime);
221 int hermite_int_test()
225 hermite<int>::time_type f;
229 etl::clock::value_type t;
239 for(f=0.0f,i=0,timer.reset();i<HERMITE_TEST_ITERATIONS;i++,f+=0.000005f)
241 t+=Hermie(f)+Hermie(f+0.1f);
242 t+=Hermie(f)+Hermie(f+0.1f);
243 t+=Hermie(f)+Hermie(f+0.1f);
244 t+=Hermie(f)+Hermie(f+0.1f);
245 t+=Hermie(f)+Hermie(f+0.1f);
246 t+=Hermie(f)+Hermie(f+0.1f);
247 t+=Hermie(f)+Hermie(f+0.1f);
248 t+=Hermie(f)+Hermie(f+0.1f);
249 t+=Hermie(f)+Hermie(f+0.1f);
250 t+=Hermie(f)+Hermie(f+0.1f);
251 t+=Hermie(f)+Hermie(f+0.1f);
252 t+=Hermie(f)+Hermie(f+0.1f);
257 printf("hermite<int>:time=%f milliseconds\n",t*1000);
261 int hermite_float_test(void)
266 hermite<float> Hermie;
278 for(f=0.0f,i=0,timer.reset();i<HERMITE_TEST_ITERATIONS;i++,f+=0.000005f)
280 t+=Hermie(f)+Hermie(f+0.1f);
281 t+=Hermie(f)+Hermie(f+0.1f);
282 t+=Hermie(f)+Hermie(f+0.1f);
283 t+=Hermie(f)+Hermie(f+0.1f);
284 t+=Hermie(f)+Hermie(f+0.1f);
285 t+=Hermie(f)+Hermie(f+0.1f);
286 t+=Hermie(f)+Hermie(f+0.1f);
287 t+=Hermie(f)+Hermie(f+0.1f);
288 t+=Hermie(f)+Hermie(f+0.1f);
289 t+=Hermie(f)+Hermie(f+0.1f);
290 t+=Hermie(f)+Hermie(f+0.1f);
291 t+=Hermie(f)+Hermie(f+0.1f);
296 printf("hermite<float>:time=%f milliseconds\n",t*1000);
300 int hermite_double_test(void)
305 hermite<double> Hermie;
316 for(f=0.0f,i=0,timer.reset();i<HERMITE_TEST_ITERATIONS;i++,f+=0.000005f)
318 t+=Hermie(f)+Hermie(f+0.1f);
319 t+=Hermie(f)+Hermie(f+0.1f);
320 t+=Hermie(f)+Hermie(f+0.1f);
321 t+=Hermie(f)+Hermie(f+0.1f);
322 t+=Hermie(f)+Hermie(f+0.1f);
323 t+=Hermie(f)+Hermie(f+0.1f);
324 t+=Hermie(f)+Hermie(f+0.1f);
325 t+=Hermie(f)+Hermie(f+0.1f);
326 t+=Hermie(f)+Hermie(f+0.1f);
327 t+=Hermie(f)+Hermie(f+0.1f);
328 t+=Hermie(f)+Hermie(f+0.1f);
329 t+=Hermie(f)+Hermie(f+0.1f);
333 printf("hermite<double>:time=%f milliseconds\n",t*1000);
337 int hermite_fixed_test(void)
341 hermite<fixed> Hermie;
342 hermite<fixed>::time_type f;
343 hermite<fixed>::time_type inc(0.0005f), inc2(1.10);
357 for(i=0,f=0,timer.reset();i<HERMITE_TEST_ITERATIONS;i++,f+=inc)
359 sum+=Hermie(f)+Hermie(f+inc2);
360 sum+=Hermie(f)+Hermie(f+inc2);
361 sum+=Hermie(f)+Hermie(f+inc2);
362 sum+=Hermie(f)+Hermie(f+inc2);
363 sum+=Hermie(f)+Hermie(f+inc2);
364 sum+=Hermie(f)+Hermie(f+inc2);
365 sum+=Hermie(f)+Hermie(f+inc2);
366 sum+=Hermie(f)+Hermie(f+inc2);
367 sum+=Hermie(f)+Hermie(f+inc2);
368 sum+=Hermie(f)+Hermie(f+inc2);
369 sum+=Hermie(f)+Hermie(f+inc2);
370 sum+=Hermie(f)+Hermie(f+inc2);
375 printf("hermite<fixed>:time=%f milliseconds\n",t*1000);
379 int hermite_angle_test(void)
384 hermite<angle> Hermie;
389 Hermie.p1()=angle::degrees(0);
390 Hermie.t1()=angle::degrees(45);
392 Hermie.p2()=angle::degrees(-45);
393 Hermie.t2()=angle::degrees(180);
397 for(f=0.0f,i=0,timer.reset();i<HERMITE_TEST_ITERATIONS;i++,f+=0.000005f)
399 tmp+=Hermie(f)+Hermie(f+0.1f);
400 tmp+=Hermie(f)+Hermie(f+0.1f);
401 tmp+=Hermie(f)+Hermie(f+0.1f);
402 tmp+=Hermie(f)+Hermie(f+0.1f);
403 tmp+=Hermie(f)+Hermie(f+0.1f);
404 tmp+=Hermie(f)+Hermie(f+0.1f);
405 tmp+=Hermie(f)+Hermie(f+0.1f);
406 tmp+=Hermie(f)+Hermie(f+0.1f);
407 tmp+=Hermie(f)+Hermie(f+0.1f);
408 tmp+=Hermie(f)+Hermie(f+0.1f);
409 tmp+=Hermie(f)+Hermie(f+0.1f);
410 tmp+=Hermie(f)+Hermie(f+0.1f);
414 fprintf(stderr,"hermite<angle>:time=%f milliseconds\n",t*1000);
419 int hermite_fastangle_test(void)
422 hermite<fastangle> Hermie;
423 hermite<fastangle>::time_type f;
429 Hermie.p1()=fastangle::degrees(0);
430 Hermie.t1()=fastangle::degrees(45);
432 Hermie.p2()=fastangle::degrees(-45);
433 Hermie.t2()=fastangle::degrees(180);
437 for(f=0.0f,i=0,timer.reset();i<HERMITE_TEST_ITERATIONS;i++,f+=0.000005f)
439 tmp+=Hermie(f)+Hermie(f+0.1f);
440 tmp+=Hermie(f)+Hermie(f+0.1f);
441 tmp+=Hermie(f)+Hermie(f+0.1f);
442 tmp+=Hermie(f)+Hermie(f+0.1f);
443 tmp+=Hermie(f)+Hermie(f+0.1f);
444 tmp+=Hermie(f)+Hermie(f+0.1f);
445 tmp+=Hermie(f)+Hermie(f+0.1f);
446 tmp+=Hermie(f)+Hermie(f+0.1f);
447 tmp+=Hermie(f)+Hermie(f+0.1f);
448 tmp+=Hermie(f)+Hermie(f+0.1f);
449 tmp+=Hermie(f)+Hermie(f+0.1f);
450 tmp+=Hermie(f)+Hermie(f+0.1f);
454 fprintf(stderr,"hermite<fastangle>:time=%f milliseconds\n",t*1000);
459 /* === E N T R Y P O I N T ================================================= */
465 error+=fastangle_speed_test();
466 error+=surface_and_gaussian_blur_test();
467 error+=hermite_float_test();
468 error+=hermite_double_test();
469 error+=hermite_int_test();
470 error+=hermite_fixed_test();
471 error+=hermite_angle_test();
472 error+=hermite_fastangle_test();