Speed in Matlab, C and Java

Here, you will find the code for the demonstrations from the class of (2/5/04). I created 4 files: Here is a transcript of my session with Matlab in which I tested these out on my workstation:
>> n = 10^6;
>> tic; x = speedTest(n); toc

elapsed_time =

    4.0123

>> tic; x = speedTest2(n); toc

elapsed_time =

    0.1522

>> tic; x = mex_speedTest(n); toc

elapsed_time =

    0.1335

>> s = SpeedTest
 
s =
 
SpeedTest@5c8569
 
>> methods(s)


Methods for class SpeedTest:


SpeedTest  getClass   notify     sumRand    wait       
equals     hashCode   notifyAll  toString   

>> tic; s.sumRand(n); toc

elapsed_time =

    0.2651


Dan Spielman
Last modified: Thu Feb 5 21:25:59 EST 2004