begin process at 2012 05 27 17:52:02
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Divers

 > POWER MATH: TESTE DE VITESSE ENTIERS VS REELS , CLASS VS STRUCT

POWER MATH: TESTE DE VITESSE ENTIERS VS REELS , CLASS VS STRUCT


 Information sur la source

Note :
Aucune note
Catégorie :Divers Classé sous :entiers, réels, vitesse, temps, chronométrage Niveau :Débutant Date de création :05/03/2010 Date de mise à jour :06/03/2010 10:25:09 Vu :1 483

Auteur : dedalusman

Ecrire un message privé
Site perso
Commentaire sur cette source (2)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
Souvent la question de la rapidité de traitement se pose et il faut faire des choix avant de commencer une application.

Dans mon cas j'ai eu besoin de tester la vitesse de différents types de variables préalablement à la programmation d'une application temps réel en 4D. Je souhaitais également vérifier si l'emploi de struct ou class ne pénalisait pas les performances.

test pour:

Les entiers 8, 16, 32 et 64 bits.
Les réels 32, 64 et 80 bits.

I/O dans un tableau, global, local, class et struct.            

Source

  • //******************
  • //*** POWER MATH ***
  • //******************
  • //Version 1.0
  • //Developed with Dev C++
  • //Programme d'evaluation de la vitesse de calcul
  • //Pour differents types de variables
  • //Affectation & operateurs
  • //Boucle de 1 milliard
  • //Test de vitesse autres fonctions
  • //By Alain Galiani
  • //Geek Star Wars 1983
  • //Alias Dedalusman
  • //nageondu@yahoo.fr
  • //Start 29 12 2009
  • //Finished 00 00 2012
  • //Last updat 05 03 2010
  • //History:
  • /*
  • Servira pour tester Geek Star Wars 1983
  • 05 03 2010 test des tableaux global local class et struct
  • */
  • #include<iostream.h>
  • #include<windows.h>
  • //definition des types
  • typedef unsigned char cop;
  • typedef signed char co;
  • typedef unsigned short m2op;
  • typedef signed short m2o;
  • typedef unsigned long lm4op;
  • typedef signed long lm4o;
  • typedef unsigned long long llm8op;
  • typedef signed long long llm8o;
  • typedef float flo4;
  • typedef double flo8;
  • typedef long double flo10;
  • //*** class ***
  • class class_objet_num
  • {
  • public:
  • //constructeur et destructeur inline
  • class_objet_num(){}
  • ~class_objet_num(){}
  • flo8 tab_sommets[1000];//x
  • };
  • class class_objet_4d
  • {
  • public:
  • //constructeur et destructeur inline
  • class_objet_4d(){}
  • ~class_objet_4d(){}
  • class_objet_num numerique;
  • };
  • //*** struct ***
  • struct struct_objet_num
  • {
  • public:
  • flo8 tab_sommets[1000];//x
  • };
  • class struct_objet_4d
  • {
  • public:
  • struct_objet_num numerique;
  • };
  • flo8 global_tab[1000];
  • flo8 gl1,gl2,gl3,gl4;
  • int main()
  • {
  • flo8 local_tab[1000];
  • flo8 lo1,lo2,lo3,lo4;
  • class_objet_4d univers[10];//univers pour 10 objets 4D
  • struct_objet_4d uni[10];//univers pour 10 objets 4D
  • //definition du ptr univers
  • class_objet_4d*ptr_univers;
  • ptr_univers=&univers[0];
  • //definition du ptr univers
  • struct_objet_4d*ptr_uni;
  • ptr_uni=&uni[0];
  • char nom[256];
  • //******************************************
  • //*** Declaration de variables entieres ***
  • //******************************************
  • //variable -128 a 127
  • co a1,a2,a3,a4,a5,a6,a7;
  • //variable -32768 a 32767
  • m2o b1,b2,b3,b4,b5,b6,b7;
  • //variable -2147483648 a 2147483647
  • lm4o c1,c2,c3,c4,c5,c6,c7;
  • //variable -9223372036854775808 a 9223372036854775807
  • llm8o d1,d2,d3,d4,d5,d6,d7;
  • //*****************************************
  • //*** Declaration de variables reelles ***
  • //*****************************************
  • //reel 32 bit
  • flo4 e1,e2,e3,e4,e5,e6,e7;
  • //reel 64 bit
  • flo8 f1,f2,f3,f4,f5,f6,f7;
  • //reel 80 bit
  • flo10 g1,g2,g3,g4,g5,g6,g7;
  • //variables divers
  • lm4op nb,nbb;
  • flo4 temcal;
  • lm4o temdeb;
  • flo4 tab_v[90][10];
  • for(nb=1;nb<90;nb++)
  • {
  • for(nbb=1;nbb<10;nbb++)
  • {
  • tab_v[nb][nbb]=1234.56;
  • }
  • }
  • cout<<"******************\n";
  • cout<<"*** POWER MATH ***\n";
  • cout<<"******************\n";
  • //goto test;
  • //test:
  • tout:
  • //***********************
  • //*** VITESSE ENTIERS ***
  • //***********************
  • cout<<"\n*** ENTIERS ***\n\n";
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • a2=45;
  • a3=-100;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • a1=a2+a3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"a1=a2+a3 "<<int(a1)<<" entier 8 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[1][1]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • b2=21024;
  • b3=-10270;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • b1=b2+b3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"b1=b2+b3 "<<b1<<" entier 16 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[1][2]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • c2=2007483647;
  • c3=-1588796587;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • c1=c2+c3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"c1=c2+c3 "<<c1<<" entier 32 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[1][3]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • d2=8223372036854775808LL;
  • d3=-1223372036854775807LL;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • d1=d2+d3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"d1=d2+d3 "<<d1<<" entier 64 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[1][4]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • a2=35;
  • a3=-3;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • a1=a2*a3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"a1=a2*a3 "<<int(a1)<<" entier 8 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[2][1]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • b2=2102;
  • b3=-11;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • b1=b2*b3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"b1=b2*b3 "<<b1<<" entier 16 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[2][2]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • c2=2007483;
  • c3=-658;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • c1=c2*c3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"c1=c2*c3 "<<c1<<" entier 32 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[2][3]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • d2=12345678901234LL;
  • d3=-12345LL;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • d1=d2*d3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"d1=d2*d3 "<<d1<<" entier 64 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[2][4]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • a2=123;
  • a3=-13;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • a1=a2/a3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"a1=a2/a3 "<<int(a1)<<" entier 8 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[3][1]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • b2=21024;
  • b3=-123;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • b1=b2/b3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"b1=b2/b3 "<<b1<<" entier 16 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[3][2]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • c2=2007483647;
  • c3=-15887;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • c1=c2/c3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"c1=c2/c3 "<<c1<<" entier 32 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[3][3]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • d2=8223372036854775808LL;
  • d3=-1223372036LL;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • d1=d2/d3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"d1=d2/d3 "<<d1<<" entier 64 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[3][4]=temcal;
  • tab_v[4][1]=tab_v[1][1]+tab_v[2][1]+tab_v[3][1];
  • tab_v[4][2]=tab_v[1][2]+tab_v[2][2]+tab_v[3][2];
  • tab_v[4][3]=tab_v[1][3]+tab_v[2][3]+tab_v[3][3];
  • tab_v[4][4]=tab_v[1][4]+tab_v[2][4]+tab_v[3][4];
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • a2=123;
  • b3=4;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • a1=a2>>b3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"a1=a2>>b3 "<<int(a1)<<" entier 8 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[5][1]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • b2=-31123;
  • b3=8;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • b1=b2>>b3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"b1=b2>>b3 "<<b1<<" entier 16 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[5][2]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • c2=2147483640;
  • b3=10;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • c1=c2>>b3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"c1=c2>>b3 "<<c1<<" entier 32 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[5][3]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • d2=-8223372036854775808LL;
  • b3=10;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • d1=d2>>b3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"d1=d2>>b3 "<<d1<<" entier 64 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[5][4]=temcal;
  • tab_v[6][1]=tab_v[5][1]+tab_v[4][1];
  • tab_v[6][2]=tab_v[5][2]+tab_v[4][2];
  • tab_v[6][3]=tab_v[5][3]+tab_v[4][3];
  • tab_v[6][4]=tab_v[5][4]+tab_v[4][4];
  • reels:
  • //*********************
  • //*** VITESSE REELS ***
  • //*********************
  • cout<<"\n*** REELS ***\n\n";
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • e2=12345.6789;
  • e3=-9876.54321;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • e1=e2+e3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"e1=e2+e3 "<<e1<<" reel 32 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[11][1]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • f2=123456789.1234567;
  • f3=-9876543.7654321;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • f1=f2+f3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"f1=f2+f3 "<<f1<<" reel 64 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[11][2]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • g2=1234567890123.123456789012;
  • g3=-9876543210.987654321;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • g1=g2+g3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"g1=g2+g3 "<<g1<<" reel 80 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[11][3]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • e2=12345.6789;
  • e3=-98.54321;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • e1=e2*e3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"e1=e2*e3 "<<e1<<" reel 32 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[12][1]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • f2=1234567.1234567;
  • f3=-987.7654321;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • f1=f2*f3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"f1=f2*f3 "<<f1<<" reel 64 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[12][2]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • g2=1234567123.123456789012;
  • g3=-98765.987654321;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • g1=g2*g3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"g1=g2*g3 "<<g1<<" reel 80 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[12][3]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • e2=12345.6789;
  • e3=-98.54321;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • e1=e2/e3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"e1=e2/e3 "<<e1<<" reel 32 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[13][1]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • f2=1234567.1234567;
  • f3=-987.7654321;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • f1=f2/f3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"f1=f2/f3 "<<f1<<" reel 64 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[13][2]=temcal;
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • g2=1234567123.123456789012;
  • g3=-98765.987654321;
  • for(nb=0;nb<1000000000;nb++)
  • {
  • g1=g2/g3;
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"g1=g2/g3 "<<g1<<" reel 80 bit 1000000000 boucles = "<<temcal<<"\n";
  • tab_v[13][3]=temcal;
  • //test:
  • tableaux:
  • //******************************************************
  • //*** VITESSE I/O TABLEAUX GLOBAL LOCAL CLASS STRUCT ***
  • //******************************************************
  • cout<<"\n*** VITESSE I/O TABLEAUX GLOBAL LOCAL CLASS STRUCT ***\n\n";
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • gl1=123456789;
  • for(nb=0;nb<1000000;nb++)
  • {
  • for(int nb2=0;nb2<1000;nb2++)
  • {
  • global_tab[nb2]=gl1;
  • gl2=global_tab[nb2];
  • }
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"flo8 global_tab[1000] entree et sortie 1000000 boucles = "<<temcal<<"\n";
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • lo1=123456789;
  • for(nb=0;nb<1000000;nb++)
  • {
  • for(int nb2=0;nb2<1000;nb2++)
  • {
  • local_tab[nb2]=lo1;
  • lo2=local_tab[nb2];
  • }
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"flo8 local_tab[1000] entree et sortie 1000000 boucles = "<<temcal<<"\n";
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • lo1=123456789;
  • for(nb=0;nb<1000000;nb++)
  • {
  • for(int nb2=0;nb2<1000;nb2++)
  • {
  • ptr_univers->numerique.tab_sommets[nb2]=lo1;
  • lo2=ptr_univers->numerique.tab_sommets[nb2];
  • }
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"flo8 CLASS univers[0].numerique.tab_sommets[1000] I/O 1000000 bcl = "<<temcal<<"\n";
  • //teste de vitesse ************************************
  • temdeb=GetTickCount();
  • lo1=123456789;
  • for(nb=0;nb<1000000;nb++)
  • {
  • for(int nb2=0;nb2<1000;nb2++)
  • {
  • ptr_uni->numerique.tab_sommets[nb2]=lo1;
  • lo2=ptr_uni->numerique.tab_sommets[nb2];
  • }
  • }
  • temcal=(float)(GetTickCount()-temdeb)/1000.;
  • cout<<"flo8 STRUCT uni[0].numerique.tab_sommets[1000] I/O 1000000 bcl = "<<temcal<<"\n";
  • tab_v[14][1]=tab_v[11][1]+tab_v[12][1]+tab_v[13][1];
  • tab_v[14][2]=tab_v[11][2]+tab_v[12][2]+tab_v[13][2];
  • tab_v[14][3]=tab_v[11][3]+tab_v[12][3]+tab_v[13][3];
  • //test:
  • cout<<"\n\n\t\t*** TABLEAU ENTIERS ***\n\n";
  • cout<<"\t\t8 bit\t16 bit\t32 bit\t64 bit\n\n";
  • for(nb=1;nb<7;nb++)
  • {
  • if(nb==1)cout<<"\t+\t";
  • if(nb==2)cout<<"\t*\t";
  • if(nb==3)cout<<"\t\\\t";
  • if(nb==4)cout<<"\n\tS_TOT\t";
  • if(nb==5)cout<<"\n\t>>\t";
  • if(nb==6)cout<<"\n\tTOTAL\t";
  • for(nbb=1;nbb<5;nbb++)
  • {
  • cout<<tab_v[nb][nbb]<<"\t";
  • }
  • cout<<"\n";
  • }
  • cout<<"\n\n\t\t*** TABLEAU REELS ***\n\n";
  • cout<<"\t\t32 bit\t64 bit\t80 bit\n\n";
  • for(nb=11;nb<15;nb++)
  • {
  • if(nb==11)cout<<"\t+\t";
  • if(nb==12)cout<<"\t*\t";
  • if(nb==13)cout<<"\t\\\t";
  • if(nb==14)cout<<"\n\tTOTAL\t";
  • for(nbb=1;nbb<4;nbb++)
  • {
  • cout<<tab_v[nb][nbb]<<"\t";
  • }
  • cout<<"\n";
  • }
  • //test:
  • cout<<"\n\nFin des calculs, entrer une commande: \"tout\" \"reels\" ou \"tableaux\" ";
  • cin>>nom;
  • if(!strcmp(nom,"tout"))
  • {
  • goto tout;
  • }
  • else
  • {
  • if(!strcmp(nom,"reels"))
  • {
  • goto reels;
  • }
  • else
  • {
  • if(!strcmp(nom,"tableaux"))
  • {
  • goto tableaux;
  • }
  • }
  • }
  • }
//******************
//*** POWER MATH ***
//******************

//Version 1.0

//Developed with Dev C++

//Programme d'evaluation de la vitesse de calcul
//Pour differents types de variables
//Affectation & operateurs 
//Boucle de 1 milliard
//Test de vitesse autres fonctions

//By Alain Galiani
//Geek Star Wars 1983 
//Alias Dedalusman
//nageondu@yahoo.fr

//Start          29 12 2009
//Finished       00 00 2012
//Last updat     05 03 2010

//History:

/*

Servira pour tester Geek Star Wars 1983

05 03 2010 test des tableaux global local class et struct


*/

#include<iostream.h>
#include<windows.h>

//definition des types

typedef unsigned char cop;
typedef signed char co;

typedef unsigned short m2op;
typedef signed short m2o;

typedef unsigned long lm4op;
typedef signed long lm4o;

typedef unsigned long long llm8op;
typedef signed long long llm8o;

typedef float flo4;
typedef double flo8;
typedef long double flo10;

//*** class ***

class class_objet_num
{
  public:

    //constructeur et destructeur inline
    class_objet_num(){}
    ~class_objet_num(){}

    flo8 tab_sommets[1000];//x
};

class class_objet_4d
{
  public:

    //constructeur et destructeur inline
    class_objet_4d(){}
    ~class_objet_4d(){}

    class_objet_num numerique;    
};

//*** struct ***

struct struct_objet_num
{
  public:
  flo8 tab_sommets[1000];//x
};

class struct_objet_4d
{
  public:
  struct_objet_num numerique;    
};

flo8 global_tab[1000];
flo8 gl1,gl2,gl3,gl4;

int main()
{

  flo8 local_tab[1000];
  flo8 lo1,lo2,lo3,lo4;

  class_objet_4d univers[10];//univers pour 10 objets 4D
  struct_objet_4d uni[10];//univers pour 10 objets 4D

  //definition du ptr univers
  class_objet_4d*ptr_univers;
  ptr_univers=&univers[0];

  //definition du ptr univers
  struct_objet_4d*ptr_uni;
  ptr_uni=&uni[0];

  char nom[256];

  //******************************************
  //***  Declaration de variables entieres ***
  //******************************************

  //variable -128 a 127
  co a1,a2,a3,a4,a5,a6,a7;

  //variable -32768 a 32767
  m2o b1,b2,b3,b4,b5,b6,b7;

  //variable -2147483648 a 2147483647
  lm4o c1,c2,c3,c4,c5,c6,c7;

  //variable -9223372036854775808 a 9223372036854775807 
  llm8o d1,d2,d3,d4,d5,d6,d7;

  //*****************************************
  //***  Declaration de variables reelles ***
  //*****************************************

  //reel 32 bit
  flo4 e1,e2,e3,e4,e5,e6,e7;

  //reel 64 bit
  flo8 f1,f2,f3,f4,f5,f6,f7;

  //reel 80 bit
  flo10 g1,g2,g3,g4,g5,g6,g7;

  //variables divers
  lm4op nb,nbb;
  flo4 temcal;
  lm4o temdeb;
  flo4 tab_v[90][10];

  for(nb=1;nb<90;nb++)
  {  
    for(nbb=1;nbb<10;nbb++)
    {
      tab_v[nb][nbb]=1234.56;
    }
  }

  cout<<"******************\n";
  cout<<"*** POWER MATH ***\n";
  cout<<"******************\n";

  //goto test;
  //test:

  tout: 

  //***********************
  //*** VITESSE ENTIERS ***
  //***********************

  cout<<"\n*** ENTIERS ***\n\n";

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  a2=45;
  a3=-100;
  for(nb=0;nb<1000000000;nb++)
  {
    a1=a2+a3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"a1=a2+a3 "<<int(a1)<<"  entier 8 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[1][1]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  b2=21024;
  b3=-10270;
  for(nb=0;nb<1000000000;nb++)
  {
    b1=b2+b3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"b1=b2+b3 "<<b1<<"  entier 16 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[1][2]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  c2=2007483647;
  c3=-1588796587;
  for(nb=0;nb<1000000000;nb++)
  {
    c1=c2+c3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"c1=c2+c3 "<<c1<<"  entier 32 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[1][3]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  d2=8223372036854775808LL;
  d3=-1223372036854775807LL;
  for(nb=0;nb<1000000000;nb++)
  {
    d1=d2+d3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"d1=d2+d3 "<<d1<<"  entier 64 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[1][4]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  a2=35;
  a3=-3;
  for(nb=0;nb<1000000000;nb++)
  {
    a1=a2*a3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"a1=a2*a3 "<<int(a1)<<"  entier 8 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[2][1]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  b2=2102;
  b3=-11;
  for(nb=0;nb<1000000000;nb++)
  {
    b1=b2*b3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"b1=b2*b3 "<<b1<<"  entier 16 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[2][2]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  c2=2007483;
  c3=-658;
  for(nb=0;nb<1000000000;nb++)
  {
    c1=c2*c3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"c1=c2*c3 "<<c1<<"  entier 32 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[2][3]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  d2=12345678901234LL;
  d3=-12345LL;
  for(nb=0;nb<1000000000;nb++)
  {
    d1=d2*d3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"d1=d2*d3 "<<d1<<"  entier 64 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[2][4]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  a2=123;
  a3=-13;
  for(nb=0;nb<1000000000;nb++)
  {
    a1=a2/a3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"a1=a2/a3 "<<int(a1)<<"  entier 8 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[3][1]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  b2=21024;
  b3=-123;
  for(nb=0;nb<1000000000;nb++)
  {
    b1=b2/b3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"b1=b2/b3 "<<b1<<"  entier 16 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[3][2]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  c2=2007483647;
  c3=-15887;
  for(nb=0;nb<1000000000;nb++)
  {
    c1=c2/c3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"c1=c2/c3 "<<c1<<"  entier 32 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[3][3]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  d2=8223372036854775808LL;
  d3=-1223372036LL;
  for(nb=0;nb<1000000000;nb++)
  {
    d1=d2/d3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"d1=d2/d3 "<<d1<<"  entier 64 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[3][4]=temcal;

  tab_v[4][1]=tab_v[1][1]+tab_v[2][1]+tab_v[3][1];
  tab_v[4][2]=tab_v[1][2]+tab_v[2][2]+tab_v[3][2];
  tab_v[4][3]=tab_v[1][3]+tab_v[2][3]+tab_v[3][3];
  tab_v[4][4]=tab_v[1][4]+tab_v[2][4]+tab_v[3][4];

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  a2=123;
  b3=4;
  for(nb=0;nb<1000000000;nb++)
  {
    a1=a2>>b3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"a1=a2>>b3 "<<int(a1)<<"  entier 8 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[5][1]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  b2=-31123;
  b3=8;
  for(nb=0;nb<1000000000;nb++)
  {
    b1=b2>>b3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"b1=b2>>b3 "<<b1<<"  entier 16 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[5][2]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  c2=2147483640;
  b3=10;
  for(nb=0;nb<1000000000;nb++)
  {
    c1=c2>>b3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"c1=c2>>b3 "<<c1<<"  entier 32 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[5][3]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  d2=-8223372036854775808LL;
  b3=10;
  for(nb=0;nb<1000000000;nb++)
  {
    d1=d2>>b3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"d1=d2>>b3 "<<d1<<"  entier 64 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[5][4]=temcal;

  tab_v[6][1]=tab_v[5][1]+tab_v[4][1];
  tab_v[6][2]=tab_v[5][2]+tab_v[4][2];
  tab_v[6][3]=tab_v[5][3]+tab_v[4][3];
  tab_v[6][4]=tab_v[5][4]+tab_v[4][4];

  reels:

  //*********************
  //*** VITESSE REELS ***
  //*********************

  cout<<"\n*** REELS ***\n\n";

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  e2=12345.6789;
  e3=-9876.54321;
  for(nb=0;nb<1000000000;nb++)
  {
    e1=e2+e3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"e1=e2+e3 "<<e1<<"  reel 32 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[11][1]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  f2=123456789.1234567;
  f3=-9876543.7654321;
  for(nb=0;nb<1000000000;nb++)
  {
    f1=f2+f3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"f1=f2+f3 "<<f1<<"  reel 64 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[11][2]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  g2=1234567890123.123456789012;
  g3=-9876543210.987654321;
  for(nb=0;nb<1000000000;nb++)
  {
    g1=g2+g3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"g1=g2+g3 "<<g1<<"  reel 80 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[11][3]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  e2=12345.6789;
  e3=-98.54321;
  for(nb=0;nb<1000000000;nb++)
  {
    e1=e2*e3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"e1=e2*e3 "<<e1<<"  reel 32 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[12][1]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  f2=1234567.1234567;
  f3=-987.7654321;
  for(nb=0;nb<1000000000;nb++)
  {
    f1=f2*f3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"f1=f2*f3 "<<f1<<"  reel 64 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[12][2]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  g2=1234567123.123456789012;
  g3=-98765.987654321;
  for(nb=0;nb<1000000000;nb++)
  {
    g1=g2*g3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"g1=g2*g3 "<<g1<<"  reel 80 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[12][3]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  e2=12345.6789;
  e3=-98.54321;
  for(nb=0;nb<1000000000;nb++)
  {
    e1=e2/e3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"e1=e2/e3 "<<e1<<"  reel 32 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[13][1]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  f2=1234567.1234567;
  f3=-987.7654321;
  for(nb=0;nb<1000000000;nb++)
  {
    f1=f2/f3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"f1=f2/f3 "<<f1<<"  reel 64 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[13][2]=temcal;

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  g2=1234567123.123456789012;
  g3=-98765.987654321;
  for(nb=0;nb<1000000000;nb++)
  {
    g1=g2/g3;
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"g1=g2/g3 "<<g1<<"  reel 80 bit 1000000000 boucles = "<<temcal<<"\n";
  tab_v[13][3]=temcal;

  //test:

  tableaux:

  //******************************************************
  //*** VITESSE I/O TABLEAUX GLOBAL LOCAL CLASS STRUCT ***
  //******************************************************

  cout<<"\n*** VITESSE I/O TABLEAUX GLOBAL LOCAL CLASS STRUCT ***\n\n";

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  gl1=123456789;
  for(nb=0;nb<1000000;nb++)
  {
    for(int nb2=0;nb2<1000;nb2++)
    {
      global_tab[nb2]=gl1;
      gl2=global_tab[nb2]; 
    }
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"flo8 global_tab[1000] entree et sortie  1000000 boucles = "<<temcal<<"\n";

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  lo1=123456789;
  for(nb=0;nb<1000000;nb++)
  {
    for(int nb2=0;nb2<1000;nb2++)
    {
      local_tab[nb2]=lo1;
      lo2=local_tab[nb2]; 
    }
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"flo8 local_tab[1000] entree et sortie  1000000 boucles = "<<temcal<<"\n";

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  lo1=123456789;
  for(nb=0;nb<1000000;nb++)
  {
    for(int nb2=0;nb2<1000;nb2++)
    {
      ptr_univers->numerique.tab_sommets[nb2]=lo1;
      lo2=ptr_univers->numerique.tab_sommets[nb2]; 
    }
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"flo8 CLASS  univers[0].numerique.tab_sommets[1000] I/O 1000000 bcl = "<<temcal<<"\n";

  //teste de vitesse ************************************
  temdeb=GetTickCount();
  lo1=123456789;
  for(nb=0;nb<1000000;nb++)
  {
    for(int nb2=0;nb2<1000;nb2++)
    {
      ptr_uni->numerique.tab_sommets[nb2]=lo1;
      lo2=ptr_uni->numerique.tab_sommets[nb2]; 
    }
  }  
  temcal=(float)(GetTickCount()-temdeb)/1000.;
  cout<<"flo8 STRUCT     uni[0].numerique.tab_sommets[1000] I/O 1000000 bcl = "<<temcal<<"\n";

  tab_v[14][1]=tab_v[11][1]+tab_v[12][1]+tab_v[13][1];
  tab_v[14][2]=tab_v[11][2]+tab_v[12][2]+tab_v[13][2];
  tab_v[14][3]=tab_v[11][3]+tab_v[12][3]+tab_v[13][3];

  //test:

  cout<<"\n\n\t\t*** TABLEAU ENTIERS ***\n\n";
  cout<<"\t\t8 bit\t16 bit\t32 bit\t64 bit\n\n";
  for(nb=1;nb<7;nb++)
  {  
    if(nb==1)cout<<"\t+\t";
    if(nb==2)cout<<"\t*\t";
    if(nb==3)cout<<"\t\\\t";
    if(nb==4)cout<<"\n\tS_TOT\t";
    if(nb==5)cout<<"\n\t>>\t";
    if(nb==6)cout<<"\n\tTOTAL\t";

    for(nbb=1;nbb<5;nbb++)
    {
      cout<<tab_v[nb][nbb]<<"\t";
    }
    cout<<"\n";
  }

  cout<<"\n\n\t\t*** TABLEAU REELS ***\n\n";
  cout<<"\t\t32 bit\t64 bit\t80 bit\n\n";
  for(nb=11;nb<15;nb++)
  {  
    if(nb==11)cout<<"\t+\t";
    if(nb==12)cout<<"\t*\t";
    if(nb==13)cout<<"\t\\\t";
    if(nb==14)cout<<"\n\tTOTAL\t";

    for(nbb=1;nbb<4;nbb++)
    {
      cout<<tab_v[nb][nbb]<<"\t";
    }
    cout<<"\n";
  }

  //test:

  cout<<"\n\nFin des calculs, entrer une commande: \"tout\" \"reels\" ou \"tableaux\" ";
  cin>>nom;

  if(!strcmp(nom,"tout"))
  {
    goto tout;
  }
  else
  {
    if(!strcmp(nom,"reels"))
    {
      goto reels;
    }
    else
    {
      if(!strcmp(nom,"tableaux"))
      {
        goto tableaux;
      }
    }
  }
}

 Conclusion

Sauf erreur de programmation de ma part, c'est extrêmement rapide.
D'autant que mes premiers ordinateurs furent un Atari 800XL puis un 520STF.


 Historique

06 mars 2010 10:25:09 :
pas de modification du code mais ajout d'une capture ecran

 Sources de la même categorie

Source avec Zip KISIEL CD INFO DRIVE par kisiel0147852
Source avec une capture SUPPRESSION DES REDONDANCES DE FICHIERS par cyberntique
Source avec Zip ÉDITEUR DE RECTANGLES EN CONSOLE par seoseo
CONVERSION DE FICHIER EN FICHIER BMP par seoseo
Source avec Zip DETECTEUR EJP par idpro

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture OP4 UN INTERPRÉTEUR POUR ENTIERS DE TRÈS GRANDE TAILLE par pgl10
Source avec Zip Source avec une capture DÉCOMPOSITION EN FACTEURS PREMIERS AVEC GMP par pgl10
Source avec Zip Source avec une capture LOGICIEL AGENDA PLANNING par BencoAndCo
Source avec Zip Source avec une capture LA FRANCE (DEVCPP) par gagah1
Source avec Zip SUDOKU AVEC BACKTRACKING ET DANCING LINK par pabbati

Commentaires et avis

Commentaire de BruNews le 06/03/2010 18:58:24 administrateur CS

for(nb=0;nb<1000000000;nb++)
{
e1=e2/e3;
}

Tu es certain que le compilo a généré le code de la boucle ???
Un compilo normal moderne vire la boucle en voyant qu'une seule opération donne le résultat. Il faut sortir le listing ASM pour etre certain.

Commentaire de dedalusman le 07/03/2010 11:57:36

Merci pour ce commentaire car je n'avait pas pensé à ce type d'optimisation des compilateurs modernes.

J'utilise Dev C++. Il est possible de voir que le temps d'exécution est en rapport avec le nombre de boucle et le type d'opération. Donc la boucle est codée. (Voir la capture écran)

La partie entière du temps indiqué est en seconde.

for(nb=0;nb<1000000000;nb++)
{
e1=e2/e3;
}

se fait en 46,953 secondes

J'obtiens (voir la capture écran) la même valeur de temps que pour:

for(nb=0;nb<1000000000;nb++)
{
f1=f2/f3;
}

Peut-être qu'un OS multitâche comme Win XP ne permet pas des mesures précises au millième de seconde étant donnée qu'il y a un basculement perpétuel entre les tâches ?

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

[Directx] Deplacement et vitesse d'une balle selon le cpu ? [ par skeleton ] Salut, voila mon probleme je me test avec directx en faisant un casse brique mais voila que je tombe sur un probleme (qui commence a me faire rager et Augmenter vitesse d'exécution [ par scelw ] Bonjour, Je "m'amuse" avec des nombres premiers de très grande taille. Le temps d'exécution de mon programme est très long. Pour aboutir, il faut souv temps d'exécution d'un processus (c/linux) [ par davidauche ] bonjour a tt monde,comment calculer le&nbsp;temps d'ex&#233;cution d'un processus en c sous linux!?j'essaie avec time et times&nbsp; + struct tms marc Vitesse de calculs [ par elflink ] Bonjour &#224; tous,Je travaille en API, C++.Je m'exerce sur l'&#233;laboration d'un outil de dessinage, et de la m&#234;me mani&#232;re que MSPAINT, Priorité et thread [ par obasileus ] Salut, j'ai un programme qui tourne avec 2 thread utilisant une m&#234;me ressource partag&#233;. Je voudrai privil&#233;gier l'execution d'un des de Lecture sur le port série en Borland C++ [ par Kurul1 ] Bonjour &#224; tousJe voudrais savoir comment faire avec Borland C++ pour lire des informations sur un port s&#233;rie. il faudrais &#233;galement que comment gerer les retour dans un fichier. [ par casper_2 ] Bonjour jaimerai que dans mon fichier,les retour chariot,soit gerer!!En faite j'aimerai qu'apr&#232;s chaque ecriture,dans le fichier il puisse m'ecri RS232 vitesse differente RX TX [ par bobnono ] Bonjour tout le monde, est-ce possible d'avoir une connexion s&#233;rie rs232 ou la reception est &#224; 32120 bauds et l'&#233;mission &#2 Comparaison De Deux Réels En C/C++ [ par Ombitious_Developper ] Salut :Je Souhaite Savoir Comment Comparer Deux R&#233;els En C/C++.En effet, Si On Consid&#232;re :float A;float B;if(A = = B){ .....}Cette Comparais Vitesse de traitement entre _write et fwrite [ par PeteTheBull ] Bonjour Dans mon programme, je sauvegarde des donn&#233;es (issues d'une acquisition video) sur mon disque soit en utilisant la fonction "_write", so


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,529 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales