X-shooter Pipeline Reference Manual 3.8.15
test-xsh_tools_perf.c
Go to the documentation of this file.
1/* *
2 * This file is part of the ESO X-shooter Pipeline *
3 * Copyright (C) 2006 European Southern Observatory *
4 * *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
18 * */
19
20/*
21 * $Author: amodigli $
22 * $Date: 2011-12-02 14:13:14 $
23 * $Revision: 1.4 $
24 * $Name: not supported by cvs2svn $
25 */
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30/*--------------------------------------------------------------------------*/
36/*--------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------
40 Includes
41 ---------------------------------------------------------------------------*/
42#include <xsh_utils.h>
43#include <xsh_error.h>
44#include <xsh_msg.h>
45#include <tests.h>
46#include <cpl.h>
47#include <math.h>
48#include <time.h>
49#include <sys/time.h>
50/*---------------------------------------------------------------------------
51 Defines
52 ---------------------------------------------------------------------------*/
53#define MODULE_ID "XSH_TOOLS_PERF"
54
55/*--------------------------------------------------------------------------*/
61/*--------------------------------------------------------------------------*/
62void test_tech_eval_perf(int indice, double val);
63
64int main(void)
65{
66 int ret = 0;
67
69 cpl_msg_set_level( CPL_MSG_DEBUG);
71 check( test_tech_eval_perf(500, 0.264879));
72 cleanup:
73 if (cpl_error_get_code() != CPL_ERROR_NONE) {
74 xsh_error_dump(CPL_MSG_ERROR);
75 ret = 1;
76 }
77 TEST_END();
78 return ret;
79}
80
81
82void test_tech_eval_perf(int indice, double val){
83 struct timeval start, end;
84 double diff_time;
85 cpl_vector* result_a = NULL;
86 cpl_vector* result_b = NULL;
87 int i=0;
88
89 xsh_msg("Test Tchebitchev polynomial eval with indice %d and val %f",
90 indice, val);
91 xsh_msg("Acos use");
92 gettimeofday(&start, NULL);
93 result_a = cpl_vector_new( indice+1);
94 for(i=0; i<= indice; i++){
95 double sval = cos(i*acos(val));
96 cpl_vector_set( result_a, i, sval);
97 }
98 gettimeofday(&end, NULL);
99 diff_time = (end.tv_sec - start.tv_sec)*1000000.0 + (end.tv_usec - start.tv_usec);
100 xsh_msg("Time %.2lf micro seconds\n", diff_time);
101
102 xsh_msg("Iterative use");
103 gettimeofday(&start, NULL);
104 check( result_b = xsh_tools_tchebitchev_poly_eval( indice, val));
105 gettimeofday(&end, NULL);
106 diff_time = (end.tv_sec - start.tv_sec)*1000000.0 + (end.tv_usec - start.tv_usec);
107 xsh_msg("Time %.2lf micro seconds\n", diff_time);
108 for(i=0; i< indice+1; i++){
109 double a, b;
110 a = cpl_vector_get( result_a,i);
111 b = cpl_vector_get( result_b,i);
112 XSH_ASSURE_NOT_ILLEGAL( fabs(a-b) < 0.0000001 );
113 }
114 cleanup:
115 xsh_free_vector( &result_a);
116 xsh_free_vector( &result_b);
117 return;
118}
int main()
Unit test of xsh_bspline_interpol.
#define XSH_ASSURE_NOT_ILLEGAL(cond)
Definition: xsh_error.h:107
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
void test_tech_eval_perf(int indice, double val)
Some test about performances.
#define MODULE_ID
void xsh_free_vector(cpl_vector **v)
Deallocate a vector and set the pointer to NULL.
Definition: xsh_utils.c:2284
int xsh_debug_level_set(int level)
set debug level
Definition: xsh_utils.c:3125
cpl_vector * xsh_tools_tchebitchev_poly_eval(int n, double X)
Compute tchebitchev Tn(X) first coefficient for tchebitchev polynomial.
Definition: xsh_utils.c:2836
#define TEST_END()
Definition: tests.h:111
#define TESTS_INIT(DRL_ID)
Definition: tests.h:105
@ XSH_DEBUG_LEVEL_MEDIUM
Definition: xsh_utils.h:138