~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to extern/ode/dist/ode/fbuild/test_dot.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kevin Roy
  • Date: 2011-02-08 22:20:54 UTC
  • mfrom: (1.4.2 upstream)
  • mto: (14.2.6 sid) (1.5.1)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: james.westby@ubuntu.com-20110208222054-kk0gwa4bu8h5lyq4
Tags: upstream-2.56.1-beta-svn34076
ImportĀ upstreamĀ versionĀ 2.56.1-beta-svn34076

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*************************************************************************
2
 
 *                                                                       *
3
 
 * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith.       *
4
 
 * All rights reserved.  Email: russ@q12.org   Web: www.q12.org          *
5
 
 *                                                                       *
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     *
12
 
 *       file LICENSE.TXT.                                               *
13
 
 *   (2) The BSD-style license that is included with this library in     *
14
 
 *       the file LICENSE-BSD.TXT.                                       *
15
 
 *                                                                       *
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.                     *
20
 
 *                                                                       *
21
 
 *************************************************************************/
22
 
 
23
 
#include <stdio.h>
24
 
#include "ode/ode.h"
25
 
 
26
 
#define ALLOCA dALLOCA16
27
 
#define SIZE 1000
28
 
 
29
 
 
30
 
// correct dot product, for accuracy testing
31
 
 
32
 
dReal goodDot (dReal *a, dReal *b, int n)
33
 
{
34
 
  dReal sum=0;
35
 
  while (n > 0) {
36
 
    sum += (*a) * (*b);
37
 
    a++;
38
 
    b++;
39
 
    n--;
40
 
  }
41
 
  return sum;
42
 
}
43
 
 
44
 
 
45
 
// test dot product accuracy
46
 
 
47
 
void testAccuracy()
48
 
{
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);
54
 
 
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");
61
 
  }
62
 
}
63
 
 
64
 
 
65
 
// test dot product factorizer speed.
66
 
 
67
 
void testSpeed()
68
 
{
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);
74
 
 
75
 
  // time several dot products, return the minimum timing
76
 
  double mintime = 1e100;
77
 
  dStopwatch sw;
78
 
  for (int i=0; i<1000; i++) {
79
 
    dStopwatchReset (&sw);
80
 
    dStopwatchStart (&sw);
81
 
 
82
 
    // try a bunch of prime sizes up to 101
83
 
    dDot (a,b,2);
84
 
    dDot (a,b,3);
85
 
    dDot (a,b,5);
86
 
    dDot (a,b,7);
87
 
    dDot (a,b,11);
88
 
    dDot (a,b,13);
89
 
    dDot (a,b,17);
90
 
    dDot (a,b,19);
91
 
    dDot (a,b,23);
92
 
    dDot (a,b,29);
93
 
    dDot (a,b,31);
94
 
    dDot (a,b,37);
95
 
    dDot (a,b,41);
96
 
    dDot (a,b,43);
97
 
    dDot (a,b,47);
98
 
    dDot (a,b,53);
99
 
    dDot (a,b,59);
100
 
    dDot (a,b,61);
101
 
    dDot (a,b,67);
102
 
    dDot (a,b,71);
103
 
    dDot (a,b,73);
104
 
    dDot (a,b,79);
105
 
    dDot (a,b,83);
106
 
    dDot (a,b,89);
107
 
    dDot (a,b,97);
108
 
    dDot (a,b,101);
109
 
 
110
 
    dStopwatchStop (&sw);
111
 
    double time = dStopwatchTime (&sw);
112
 
    if (time < mintime) mintime = time;
113
 
  }
114
 
 
115
 
  printf ("%.0f",mintime * dTimerTicksPerSecond());
116
 
}
117
 
 
118
 
 
119
 
int main()
120
 
{
121
 
  testAccuracy();
122
 
  testSpeed();
123
 
  return 0;
124
 
}