Post Undeleted by Shan, revo, Mihai Alexandru-Ionut
Active reading [<http://en.wikipedia.org/wiki/MATLAB>]
Source Link
Peter Mortensen
  • 30.3k
  • 21
  • 100
  • 124

I tried the same code with MatlabMATLAB 2011b with my MacBook Pro ( IntelIntel i7, 64 bit, 2.4 GHz) for the following matlabMATLAB code:

% Processing time with Sorted data vs unsorted data
%==========================================================================
% Generate data
arraySize = 32768
sum =0;= 0;
%generate% Generate random integer data from range 0  to 255
data = randi(256, arraySize, 1);  


%Sort the data 
data1= sort(data); % data1= data  when no sorting done


%Start a stopwatch timer to measure the execution time 
tic;

for i=1:100000
    
    for j=1:arraySize
        
        if data1(j)>=128
            sum=sum + data1(j);           
        end
        
    end
end

toc;

ExeTimeWithSorting=ExeTimeWithSorting = toc - tic;

The results for the above MatlabMATLAB code areare as follows:

  a: Elapsed time (without sorting) = 3479.880861 seconds. 
  b: Elapsed time (with sorting ) = 2377.873098 seconds. 

The results of the C code as in @GManNickG II get  :

  a: Elapsed time (without sorting) = 19.8761 sec. 
  b: Elapsed time (with sorting ) = 7.37778 sec. 

Based on this, it looks MatlabMATLAB is almost 175 times175 times slower than the C implementation without sorting andand 350 times350 times slower with sorting. In other words, thethe effect (of branch prediction) is 1.46x1.46x for MatlabMATLAB implementation and 2.7x2.7x for the C implementation.

I tried the same code with Matlab 2011b with my MacBook Pro ( Intel i7, 64 bit, 2.4 GHz) for the following matlab code:

% Processing time with Sorted data vs unsorted data
%==========================================================================
% Generate data
arraySize = 32768
sum =0;
%generate random integer data from range 0  to 255
data = randi(256,arraySize,1);  


%Sort the data 
data1= sort(data); % data1= data  when no sorting done


%Start a stopwatch timer to measure the execution time 
tic;

for i=1:100000
    
    for j=1:arraySize
        
        if data1(j)>=128
            sum=sum + data1(j);           
        end
        
    end
end

toc;

ExeTimeWithSorting= toc -tic;

The results for the above Matlab code are as follows:

  a: Elapsed time (without sorting) = 3479.880861 seconds. 
  b: Elapsed time (with sorting ) = 2377.873098 seconds. 

The results of the C code as in @GManNickG I get  :

  a: Elapsed time (without sorting) = 19.8761 sec. 
  b: Elapsed time (with sorting ) = 7.37778 sec. 

Based on this, it looks Matlab is almost 175 times slower than C implementation without sorting and 350 times slower with sorting. In other words, the effect (of branch prediction) is 1.46x for Matlab implementation and 2.7x for C implementation.

I tried the same code with MATLAB 2011b with my MacBook Pro (Intel i7, 64 bit, 2.4 GHz) for the following MATLAB code:

% Processing time with Sorted data vs unsorted data
%==========================================================================
% Generate data
arraySize = 32768
sum = 0;
% Generate random integer data from range 0 to 255
data = randi(256, arraySize, 1);


%Sort the data
data1= sort(data); % data1= data  when no sorting done


%Start a stopwatch timer to measure the execution time
tic;

for i=1:100000

    for j=1:arraySize

        if data1(j)>=128
            sum=sum + data1(j);
        end
    end
end

toc;

ExeTimeWithSorting = toc - tic;

The results for the above MATLAB code are as follows:

  a: Elapsed time (without sorting) = 3479.880861 seconds.
  b: Elapsed time (with sorting ) = 2377.873098 seconds.

The results of the C code as in @GManNickG I get:

  a: Elapsed time (without sorting) = 19.8761 sec.
  b: Elapsed time (with sorting ) = 7.37778 sec.

Based on this, it looks MATLAB is almost 175 times slower than the C implementation without sorting and 350 times slower with sorting. In other words, the effect (of branch prediction) is 1.46x for MATLAB implementation and 2.7x for the C implementation.

Mod Removes Wiki by Shog9
Post Made Community Wiki by George Stocker
Post Deleted by casperOne
edited body
Source Link
Shan
  • 4.9k
  • 12
  • 43
  • 58

I tried the same code with Matlab 2011b with my MacBook Pro ( Intel i7, 64 bit, 2.4 GHz) for the following matlab code:

% Processing time with Sorted data vs unsorted data
%==========================================================================
% Generate data
arraySize = 32768
sum =0;
%generate random integer data from ramgerange 0  to 255
data = randi(256,arraySize,1);  


%Sort the data 
data1= sort(data); % data1= data  when no sorting done


%Start a stopwatch timer to measure the execution time 
tic;

for i=1:100000
    
    for j=1:arraySize
        
        if data1(j)>=128
            sum=sum + data1(j);           
        end
        
    end
end

toc;

ExeTimeWithSorting= toc -tic;

The results for the above Matlab code are as follows:

  a: Elapsed time (without sorting) = 3479.880861 seconds. 
  b: Elapsed time (with sorting ) = 2377.873098 seconds. 

The results of the C code as in @GManNickG I get :

  a: Elapsed time (without sorting) = 19.8761 sec. 
  b: Elapsed time (with sorting ) = 7.37778 sec. 

Based on this, it looks Matlab is almost 175 times slower than C implementation without sorting and 350 times slower with sorting. In other words, the effect (of branch prediction) is 1.46x for Matlab implementation and 2.7x for C implementation.

I tried the same code with Matlab 2011b with my MacBook Pro ( Intel i7, 64 bit, 2.4 GHz) for the following matlab code:

% Processing time with Sorted data vs unsorted data
%==========================================================================
% Generate data
arraySize = 32768
sum =0;
%generate random integer data from ramge 0  to 255
data = randi(256,arraySize,1);  


%Sort the data 
data1= sort(data); % data1= data  when no sorting done


%Start a stopwatch timer to measure the execution time 
tic;

for i=1:100000
    
    for j=1:arraySize
        
        if data1(j)>=128
            sum=sum + data1(j);           
        end
        
    end
end

toc;

ExeTimeWithSorting= toc -tic;

The results for the above Matlab code are as follows:

  a: Elapsed time (without sorting) = 3479.880861 seconds. 
  b: Elapsed time (with sorting ) = 2377.873098 seconds. 

The results of the C code as in @GManNickG I get :

  a: Elapsed time (without sorting) = 19.8761 sec. 
  b: Elapsed time (with sorting ) = 7.37778 sec. 

Based on this, it looks Matlab is almost 175 times slower than C implementation without sorting and 350 times slower with sorting. In other words, the effect (of branch prediction) is 1.46x for Matlab implementation and 2.7x for C implementation.

I tried the same code with Matlab 2011b with my MacBook Pro ( Intel i7, 64 bit, 2.4 GHz) for the following matlab code:

% Processing time with Sorted data vs unsorted data
%==========================================================================
% Generate data
arraySize = 32768
sum =0;
%generate random integer data from range 0  to 255
data = randi(256,arraySize,1);  


%Sort the data 
data1= sort(data); % data1= data  when no sorting done


%Start a stopwatch timer to measure the execution time 
tic;

for i=1:100000
    
    for j=1:arraySize
        
        if data1(j)>=128
            sum=sum + data1(j);           
        end
        
    end
end

toc;

ExeTimeWithSorting= toc -tic;

The results for the above Matlab code are as follows:

  a: Elapsed time (without sorting) = 3479.880861 seconds. 
  b: Elapsed time (with sorting ) = 2377.873098 seconds. 

The results of the C code as in @GManNickG I get :

  a: Elapsed time (without sorting) = 19.8761 sec. 
  b: Elapsed time (with sorting ) = 7.37778 sec. 

Based on this, it looks Matlab is almost 175 times slower than C implementation without sorting and 350 times slower with sorting. In other words, the effect (of branch prediction) is 1.46x for Matlab implementation and 2.7x for C implementation.

added 4 characters in body
Source Link
Shan
  • 4.9k
  • 12
  • 43
  • 58

I tried the same code with Matlab 2011b with my MacBook Pro ( Intel i7, 64 bit, 2.4 GHz) for the following matlab code:

% Processing time with Sorted data vs unsorted data
%==========================================================================
% Generate data
arraySize = 32768
sum =0;
%generate random integer data from ramge 0  to 255
data = randi(256,arraySize,1);  


%Sort the data 
data1= sort(data); % data1= data  when no sorting done


%Start a stopwatch timer to measure the execution time 
tic;

for i=1:100000
    
    for j=1:arraySize
        
        if data1(j)>=128
            sum=sum + data1(j);           
        end
        
    end
end

toc;

ExeTimeWithSorting= toc -tic;

The results for the above Matlab code as are as follows:

  a: Elapsed time (without sorting) = 3479.880861 seconds. 
  b: Elapsed time (with sorting ) = 2377.873098 seconds. 

The results of the C code as in @GManNickG I get :

  a: Elapsed time (without sorting) = 19.8761 sec. 
  b: Elapsed time (with sorting ) = 7.37778 sec. 

Based on this, it looks Matlab is almost 175 times slower than C implementation without sorting and 350 times slower with sorting. In other words, the effect (of branch prediction) is 1.46x for Matlab implementation and 2.7x for C implementation.

I tried the same code with Matlab 2011b with my MacBook Pro ( Intel i7, 64 bit, 2.4 GHz) for the following matlab code:

% Processing time with Sorted data vs unsorted data
%==========================================================================
% Generate data
arraySize = 32768
sum =0;
%generate random integer data from ramge 0  to 255
data = randi(256,arraySize,1);  


%Sort the data 
data1= sort(data); % data1= data  when no sorting done


%Start a stopwatch timer to measure the execution time 
tic;

for i=1:100000
    
    for j=1:arraySize
        
        if data1(j)>=128
            sum=sum + data1(j);           
        end
        
    end
end

toc;

ExeTimeWithSorting= toc -tic;

The results for the above Matlab code as follows:

  a: Elapsed time (without sorting) = 3479.880861 seconds. 
  b: Elapsed time (with sorting ) = 2377.873098 seconds. 

The results of the C code as in @GManNickG I get :

  a: Elapsed time (without sorting) = 19.8761 sec. 
  b: Elapsed time (with sorting ) = 7.37778 sec. 

Based on this, it looks Matlab is almost 175 times slower than C implementation without sorting and 350 times slower with sorting. In other words, the effect (of branch prediction) is 1.46x for Matlab implementation and 2.7x for C implementation.

I tried the same code with Matlab 2011b with my MacBook Pro ( Intel i7, 64 bit, 2.4 GHz) for the following matlab code:

% Processing time with Sorted data vs unsorted data
%==========================================================================
% Generate data
arraySize = 32768
sum =0;
%generate random integer data from ramge 0  to 255
data = randi(256,arraySize,1);  


%Sort the data 
data1= sort(data); % data1= data  when no sorting done


%Start a stopwatch timer to measure the execution time 
tic;

for i=1:100000
    
    for j=1:arraySize
        
        if data1(j)>=128
            sum=sum + data1(j);           
        end
        
    end
end

toc;

ExeTimeWithSorting= toc -tic;

The results for the above Matlab code are as follows:

  a: Elapsed time (without sorting) = 3479.880861 seconds. 
  b: Elapsed time (with sorting ) = 2377.873098 seconds. 

The results of the C code as in @GManNickG I get :

  a: Elapsed time (without sorting) = 19.8761 sec. 
  b: Elapsed time (with sorting ) = 7.37778 sec. 

Based on this, it looks Matlab is almost 175 times slower than C implementation without sorting and 350 times slower with sorting. In other words, the effect (of branch prediction) is 1.46x for Matlab implementation and 2.7x for C implementation.

added 4 characters in body
Source Link
Shan
  • 4.9k
  • 12
  • 43
  • 58
Loading
deleted 5 characters in body
Source Link
Shan
  • 4.9k
  • 12
  • 43
  • 58
Loading
added 252 characters in body
Source Link
Shan
  • 4.9k
  • 12
  • 43
  • 58
Loading
Source Link
Shan
  • 4.9k
  • 12
  • 43
  • 58
Loading