File: vdtArithmBenchmark.cpp

package info (click to toggle)
vdt 0.4.4-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 620 kB
  • sloc: cpp: 2,382; ansic: 1,589; python: 1,126; csh: 16; makefile: 8
file content (221 lines) | stat: -rw-r--r-- 6,958 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/* vdtArithmBenchmark.cpp
*
*	created: 13.7.2012
*
*	Dumps fcnResponce of every function to the file.
*	Created for bunch-testing as preceeding step to the
*	bunch-fcnComparison
*
*	Author: Ladislav Horky
*/

#include "vdtMath.h"
#include "vdtdiag_random.h"
#include "vdtdiag_fcnResponse.h"
#include "vdtdiag_fcnTuples.h"
#include "vdtdiag_simpleCmd.h"

#include <iostream>
#include <string>

const double spool_max = 5000; //1.0e8;
const double spool_min = -spool_max;
const double ppool_min = .0001; //1e-10;

const float spool_maxf = 5000;//8192;
const float spool_minf = -spool_maxf;
const float ppool_minf = .0001f;//8192;


template<typename T, template<class> class Tuple>
void saveResponses(const Tuple<T>& fcn_tuple, const std::string nickname){
	fcnResponse<T> response(std::get<0>(fcn_tuple),std::get<2>(fcn_tuple),std::get<1>(fcn_tuple));
	// create filename: <nickname>_<fcnname>_response.txt
	std::string fname = nickname;
	// two dashes to prevent i.e Fast_something mess
	fname += "__";
	fname += std::get<0>(fcn_tuple);
	fname += "__response.txt";
	// dump to file
	response.writeFile(fname);
}

template<typename T,class FUNC>
void saveResponses2D(const std::string& fcn_name,
        			 FUNC fcn,
		             const std::vector<T>& randomX,
		             const std::vector<T>& randomY,
		             const std::string& nickname){
	fcnResponse2D<T> response(fcn_name, randomX,randomY,fcn);
	// create filename: <nickname>_<fcnname>_response.txt
	std::string fname = nickname;
	// two dashes to prevent i.e Fast_something mess
	fname += "__";
	fname += fcn_name;
	fname += "__response.txt";
	// dump to file
	response.writeFile(fname);
}


int main(int argc, char **argv){

	// set and parse commandline options
	CmdOptions opt;
	opt.addOption("-n","--nick","Nickname to distinguish different runs/libraries used (required)");
	opt.addOption("-s","--size","# of numbers to be tested (default 50000)");

	std::string nick = " ";
	uint32_t SIZE = 50000;

	if(!opt.parseCmd(argc,argv)){
		std::cout << "Something is wrong with cmd options, try --help\n"
			<<"usage: vdtArithmBenchmark -n=<run88>";
		return 0;
	}
	// if help was printed, exit
	if(opt.isSet("-h"))
		return 1;

	// process cmd options
	nick = opt.getArgument("-n");
	if(nick == ""){
		std::cout << "Error: Nickname was not specified!\n";
		opt.printHelp("-n");
		return 0;
	}
	

	//getArgument() contains isSet check 
	if(opt.getArgument("-s") != "")
		SIZE = atoi(opt.getArgument("-s").c_str());

	// print basic info
	std::cout << "Nick = " << nick << ", size = " << SIZE << "\n";
	std::cout<<"Starting...\n";

	randomPool<double> *spool,*ppool,*onepool,*exppool;
	randomPool2D<double> *spool2D;
	spool = new randomPool<double>(spool_min,spool_max,SIZE);
	spool2D = new randomPool2D<double>(-1.,-1.,1.,1.,SIZE);
	ppool = new randomPool<double>(ppool_min,spool_max,SIZE);
	onepool = new randomPool<double>(-1.0,1.0,SIZE);
	exppool = new randomPool<double>(-705.,705.,SIZE);

	//======================DP=========================
	std::vector<genfpfcn_tuple<double>> dpTuples;

	//retrieve tuples
	getFunctionTuples(&dpTuples,*spool,*ppool,*onepool,*exppool);

	//loop over & save to file
	std::cout <<"Saving double precision\n";
	for(const auto& i_tuple : dpTuples){
                std::cout << " - Processing " << std::get<0>(i_tuple) << std::endl;
		saveResponses<double,genfpfcn_tuple>(i_tuple,nick);
                }

	//========================DPv======================
	std::vector<genfpfcnv_tuple<double>> dpvTuples;

	//retrieve tuples
	getFunctionTuplesvect(&dpvTuples,*spool,*ppool,*onepool,*exppool);

	//loop over & save to file
	std::cout <<"Saving double precision vector form\n";
	for(const auto& i_tuple : dpvTuples){
                std::cout << " - Processing " << std::get<0>(i_tuple) << std::endl;
		saveResponses<double,genfpfcnv_tuple>(i_tuple,nick);
        }

	// Add atan2
	std::cout << " - Processing atan2 (all flavours)\n";
	saveResponses2D<double,vdth::dpdp2function> ("Atan2",
    		refMath::atan2,
    		spool2D->getNumbersX(),spool2D->getNumbersY(),
    		nick);
    saveResponses2D<double,vdth::dpdp2function> ("Fast_Atan2",
    		vdt::fast_atan2,
    		spool2D->getNumbersX(),spool2D->getNumbersY(),
    		nick);

    saveResponses2D<double,vdth::dpdp2functionv> ("Atan2v",
    		vdt::atan2v,
    		spool2D->getNumbersX(),spool2D->getNumbersY(),
    		nick);
    saveResponses2D<double,vdth::dpdp2functionv> ("Fast_Atan2v",
    		vdt::fast_atan2v,
    		spool2D->getNumbersX(),spool2D->getNumbersY(),
    		nick);

	//delete to spare memeory..
	delete spool;
	delete ppool;
	delete onepool;
	delete exppool;
	delete spool2D;

	randomPool<float>* fspool,*fppool,*fonepool,*fexppool;
	randomPool2D<float>* fspool2D;
	fspool = new randomPool<float>(spool_minf,spool_maxf,SIZE);
	fppool = new randomPool<float>(ppool_minf,spool_maxf,SIZE);
	fonepool = new randomPool<float>(-1.0,1.0,SIZE);
	fexppool = new randomPool<float>(-85,85,SIZE);
	fspool2D = new randomPool2D<float>(-1.f,-1.f,1.f,1.f,SIZE);

	//======================SP=========================
	std::vector<genfpfcn_tuple<float>> spTuples;

	//retrieve tuples
	getFunctionTuples(&spTuples,*fspool,*fppool,*fonepool,*fexppool);

	//loop over & save to file
	std::cout <<"Saving single precision\n";
	for(const auto& i_tuple : spTuples){
                std::cout << " - Processing " << std::get<0>(i_tuple) << std::endl;
		saveResponses<float,genfpfcn_tuple>(i_tuple,nick);
        }

	//======================SPv=========================
	std::vector<genfpfcnv_tuple<float>> spvTuples;

	//retrieve tuples
	getFunctionTuplesvect(&spvTuples,*fspool,*fppool,*fonepool,*fexppool);

	//loop over & save to file
	std::cout <<"Saving single precision vector form\n";
	for(const auto& i_tuple : spvTuples){
                std::cout << " - Processing " << std::get<0>(i_tuple) << std::endl;
		saveResponses<float,genfpfcnv_tuple>(i_tuple,nick);
        }

	// Add atan2
	std::cout << " - Processing atan2 (all flavours)\n";
    saveResponses2D<float,vdth::spsp2function> ("Atan2f",
    		refMath::atan2f,
    		fspool2D->getNumbersX(),fspool2D->getNumbersY(),
    		nick);
    saveResponses2D<float,vdth::spsp2function> ("Fast_Atan2f",
    		vdt::fast_atan2f,
    		fspool2D->getNumbersX(),fspool2D->getNumbersY(),
    		nick);
    saveResponses2D<float,vdth::spsp2functionv> ("Atan2fv",
    		vdt::atan2fv,
    		fspool2D->getNumbersX(),fspool2D->getNumbersY(),
    		nick);
    saveResponses2D<float,vdth::spsp2functionv> ("Fast_Atan2fv",
    		vdt::fast_atan2fv,
    		fspool2D->getNumbersX(),fspool2D->getNumbersY(),
    		nick);


	//delete to spare memeory
	delete fspool;
	delete fppool;
	delete fonepool;
	delete fexppool;
	delete fspool2D;

	return 0;
}