Bonjour, suite au code fournie par flyweight
http://www.developpez.net/forums/sho...55&postcount=8
j'ai testé avec GCC pour voir les différences de performance... ET le cos de asm est plus rapide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
#include <iostream>
#include <cmath>
#include <ctime>
#include <vector>
#include <limits>
 
using namespace std;
 
inline float asm_cos( float  x)
{
    asm ("fcos" : "=t" (x) : "0" (x));
    return x;
}
 
 
int main()
{
    clock_t time1;
    clock_t time2;
    clock_t time3;
    clock_t time4;
    const int nbCalcul = 10000000;
    vector<float> test_cos(nbCalcul);
    double somme(0);
    for (int  i=0;i<nbCalcul;++i)
              somme+= fabs( cosf(static_cast<float>(i*2.f*M_PI/(nbCalcul-1)))-asm_cos(static_cast<float>(i*2.f*M_PI/(nbCalcul-1))));
    cout << "moyenne difference "<< somme/nbCalcul << endl;
    cout << "epsilon float "<< numeric_limits<float>::epsilon() << endl;
 
 
    for (int j=0;j<10;++j)
        {
        int i;
        time1 = clock();
        for ( i=0;i<nbCalcul;++i)
              test_cos[i] = cosf(static_cast<float>(i*2.f*M_PI/(nbCalcul-1)));
        time2 = clock();
 
        for (i=0;i<nbCalcul;++i)
                test_cos[i] = asm_cos(static_cast<float>(i*2.f*M_PI/(nbCalcul-1)));
        time3 = clock();
 
        time4 = clock();
        cout << "cos "<< static_cast<double>(time2 - time1) / CLOCKS_PER_SEC << endl;
        cout << "asm_cos "<<static_cast<double>(time3 - time2) / CLOCKS_PER_SEC << endl<< endl;
 
        }
 
 
    return 0;
}
La différences de résultat entre les cos semble négligeable (moyenne des differences < epsilon d'un float).
Ai je fait une erreur? Es ce que j'interprète mal les résultats?

Si quelqu'un à une réponse