Announcement

Collapse
No announcement yet.

Geschwindigkeitsmessung int MultiArray

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Geschwindigkeitsmessung int MultiArray

    Guten Abend Community

    Hab hier eine Zeitmessung gefunden,

    die ich noch ein bisschen erweitert habe. Vorläufig nur mit int Array und int Multiarray. Vielleicht kanns jemand brauchen.

    Freundliche Grüsse

    exc-jdbi


    Code:
    // ZeiterfassungArray.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
    //http://forums.devshed.com/programming-42/convert-vector-dynamic-multidimensional-array-775836.html
    
    
    #include "stdafx.h"
    #include <vector>
    #include <iostream>
    #include <Windows.h>
    
    
    //using namespace System;
    using namespace std;
    
    void witharray();
    void dynamicVector();
    void staticVector();
    void dynamicVectorWithReserve();
    void dynamicVectorWithResize();
    void MultiWitharray();
    void MultidynamicVector();
    void MultistaticVector();
    void MultidynamicVectorWithReserve();
    void MultidynamicVectorWithResize();
    
    #define int_nMax  447	//Wurzel(200000)
    #define int_Max 200000
    
    
    //int _tmain(int argc, _TCHAR* argv[])
    int main()
    {
        cout<<"Arrays"<<endl;
    	cout<<"******"<<endl<<endl;
    
    	witharray(); 
        dynamicVector();
        staticVector();
        dynamicVectorWithReserve();
        dynamicVectorWithResize();
    
    	cout<<endl<<endl;
     	cout<<"MultiArrays"<<endl;
    	cout<<"***********"<<endl<<endl;
    
    	MultiWitharray();
    	MultidynamicVector();
    	MultistaticVector();
    	MultidynamicVectorWithReserve();
    	MultidynamicVectorWithResize();
    
    
        cout <<endl;
       system("pause");
    return 0;
    }
    
    void witharray()
    {
       unsigned long StartTime = GetTickCount();
    
       
       for (int j=0;j<10;j++){
       	int a[int_Max];
    	 	
    		  for (int i=0;i<int_Max;i++){
    			  a[i] = i*2-i;
    		  }	 
       }
    
    unsigned long EndTime = GetTickCount();
    unsigned long TimerValMS = EndTime - StartTime; // time in ms
    
    cout<<endl<<"With array:  "<< TimerValMS<<endl;
    
    return;
    }
    
    void dynamicVector()
    {
     unsigned long StartTime = GetTickCount();
    	
     for (int j=0;j<10;j++)
     {
    	vector<int> a;
    
    	for (int i=0;i<int_Max;i++)
    	{
    	   	a.push_back(i*2-i);
        }
    
    }
    
    unsigned long EndTime = GetTickCount();
    unsigned long TimerValMS = EndTime - StartTime; // time in ms
    
    
    cout<<endl<<"Dynamic vector with push_back:  "<< TimerValMS<<endl;
    
    return;
    }
    
    void staticVector()
    {
     unsigned long StartTime = GetTickCount();
    	
     for (int j=0;j<10;j++) 
     {
      
         vector<int> a(int_Max);
    	  for (int i=0;i<int_Max;i++)
    		  {
    			a[i]=i*2-i;
    	      }
     }
    
    unsigned long EndTime = GetTickCount();
    unsigned long TimerValMS = EndTime - StartTime; // time in ms
    
    cout<<endl<<"Static vector without push_back:  "<< TimerValMS;
    
    
    return;
    }
    
     void dynamicVectorWithReserve()
     {
      unsigned long StartTime = GetTickCount();
    	
       for (int j=0;j<10;j++)
       {
         vector <int> a;
    	 a.reserve(int_Max);
    
    	for (int i=0;i<int_Max;i++)
    	{
    	   	a.push_back(i*2-i);
        }
       }
    
    unsigned long EndTime = GetTickCount();
    unsigned long TimerValMS = EndTime - StartTime; // time in ms
    
    cout<<endl<<"Dynamic vector with push_back:- reserve: "<< TimerValMS<<endl;
    
    return;
    
     }
    
     void dynamicVectorWithResize()
     {
    
    	unsigned long StartTime = GetTickCount();
     
    	 for (int j=0;j<10;j++)
    	 {
    		vector <int> a;
    		a.resize(int_Max);
    
    		for (int i=0;i<int_Max;i++)
    		{
    		  a[i]= i*2-i ;
    		}
    	}
    
    unsigned long EndTime = GetTickCount();
    unsigned long TimerValMS = EndTime - StartTime; // time in ms
    
    cout<<endl<<"Dynamic vector without push_back:- resize :  "<< TimerValMS<<endl<<endl;
    
    return;
    
     }
    
     void MultiWitharray()
    {
       unsigned long StartTime = GetTickCount();
    
    
       for (int j=0;j<10;j++)
       {
       	int a[int_nMax][int_nMax];
    	 	
    		  for (int i=0;i<int_nMax;i++){
    			 for(int jj=0;jj<int_nMax;jj++)
    			    a[i][jj] = i*2-i;
    			}
    	 
       }
    
    unsigned long EndTime = GetTickCount();
    unsigned long TimerValMS = EndTime - StartTime; // time in ms
    
    cout<<endl<<"With Multiarray:  "<< TimerValMS<<endl;
    
    return;
    }
    
     void MultidynamicVector()
    {
     unsigned long StartTime = GetTickCount();
     
     const int rows = int_nMax;
     const int columns = int_nMax;
    
     for (int j=0;j<10;j++){
    	vector< vector<int>>a;	
    	for (int i=0;i<int_nMax;i++){
    		vector<int> row;
    		for (int jj = 0; jj < int_nMax; jj++) {
    			row.push_back(i*2-i);
    		}
    		a.push_back(row);
        }
    
    }
    
    unsigned long EndTime = GetTickCount();
    unsigned long TimerValMS = EndTime - StartTime; // time in ms
    
    
    cout<<endl<<"Dynamic Multivector with push_back:  "<< TimerValMS<<endl;
    
    return;
    }
    
     void MultistaticVector()
    {
     unsigned long StartTime = GetTickCount();
    	
     for (int j=0;j<10;j++) 
     {
    	 vector<vector<int>>a(int_nMax,vector<int>(int_nMax));	
         //vector<int> a(int_Max);
    	  for(int i=0;i<int_nMax;i++){
    		  for(int jj=0;jj<int_nMax;jj++){
    			a[i][j]=i*2-i;
    	      }
    	  }
     }
    
    unsigned long EndTime = GetTickCount();
    unsigned long TimerValMS = EndTime - StartTime; // time in ms
    
    cout<<endl<<"Static Multivector without push_back:  "<< TimerValMS;
    
    
    return;
    }
    
     void MultidynamicVectorWithReserve()
     {
      unsigned long StartTime = GetTickCount();
    	
      vector< vector<int>>a;
      a.reserve(int_nMax*int_nMax);
      for (int i=0;i<int_nMax;i++){
    	  vector<int> row;
    	  for (int jj = 0; jj < int_nMax; jj++) {
    		  row.push_back(i*2-i);
    	  }
    	  a.push_back(row);
      }
    
    unsigned long EndTime = GetTickCount();
    unsigned long TimerValMS = EndTime - StartTime; // time in ms
    
    cout<<endl<<"Dynamic Multivector with push_back:- reserve: "<< TimerValMS<<endl;
    
    return;
    
     }
    
     void MultidynamicVectorWithResize(){
    
    	unsigned long StartTime = GetTickCount();
    	
    	const int rows = int_nMax;
    	const int columns = int_nMax;
    
    	 for (int j=0;j<10;j++)
    	 {
    		vector <int> a;
    		a.resize(rows * columns);
    
    		for (int row = 0; row < rows; row++) {
    			for (int col = 0; col < columns; col++) {
    				a[row * columns + col] = row * 2 - col;
    			}
    		}
    	 }
    
    unsigned long EndTime = GetTickCount();
    unsigned long TimerValMS = EndTime - StartTime; // time in ms
    
    cout<<endl<<"Dynamic Multivector without push_back:- resize :  "<< TimerValMS<<endl<<endl;
    
    return;
    
     }
Working...
X