1
/*************************************************************************
3
* Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4
* All rights reserved. Email: russ@q12.org Web: www.q12.org *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of EITHER: *
8
* (1) The GNU Lesser General Public License as published by the Free *
9
* Software Foundation; either version 2.1 of the License, or (at *
10
* your option) any later version. The text of the GNU Lesser *
11
* General Public License is included with this library in the *
13
* (2) The BSD-style license that is included with this library in *
14
* the file LICENSE-BSD.TXT. *
16
* This library is distributed in the hope that it will be useful, *
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19
* LICENSE.TXT and LICENSE-BSD.TXT for more details. *
21
*************************************************************************/
26
#define ALLOCA dALLOCA16
30
// correct dot product, for accuracy testing
32
dReal goodDot (dReal *a, dReal *b, int n)
45
// test dot product accuracy
49
// allocate vectors a and b and fill them with random data
50
dReal *a = (dReal*) ALLOCA (SIZE*sizeof(dReal));
51
dReal *b = (dReal*) ALLOCA (SIZE*sizeof(dReal));
52
dMakeRandomMatrix (a,1,SIZE,1.0);
53
dMakeRandomMatrix (b,1,SIZE,1.0);
55
for (int n=1; n<100; n++) {
56
dReal good = goodDot (a,b,n);
57
dReal test = dDot (a,b,n);
58
dReal diff = fabs(good-test);
59
//printf ("diff = %e\n",diff);
60
if (diff > 1e-10) printf ("ERROR: accuracy test failed\n");
65
// test dot product factorizer speed.
69
// allocate vectors a and b and fill them with random data
70
dReal *a = (dReal*) ALLOCA (SIZE*sizeof(dReal));
71
dReal *b = (dReal*) ALLOCA (SIZE*sizeof(dReal));
72
dMakeRandomMatrix (a,1,SIZE,1.0);
73
dMakeRandomMatrix (b,1,SIZE,1.0);
75
// time several dot products, return the minimum timing
76
double mintime = 1e100;
78
for (int i=0; i<1000; i++) {
79
dStopwatchReset (&sw);
80
dStopwatchStart (&sw);
82
// try a bunch of prime sizes up to 101
110
dStopwatchStop (&sw);
111
double time = dStopwatchTime (&sw);
112
if (time < mintime) mintime = time;
115
printf ("%.0f",mintime * dTimerTicksPerSecond());