Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.89 KB | None | 0 0
  1. using BenchmarkTools;
  2. using LinearAlgebra;
  3. using Statistics;
  4.  
  5. function SimpleMatrixOperation( mX )
  6.     mY = (2 .* mX) + (mX .^ 2);
  7.     mA, mB = eigen(mX);
  8.     svdF = svd(mX);
  9.  
  10.     return mY .+ mA .+ mB .+ svdF.U;
  11. end
  12.  
  13. function MeasureTimeIterations( mX, numIterations )
  14.     vRunTime = zeros(numIterations);
  15.  
  16.     for ii = 1:numIterations
  17.         vRunTime[ii] = @elapsed begin
  18.             mA = SimpleMatrixOperation(mX);
  19.         end
  20.     end
  21.  
  22.     runTime = minimum(vRunTime);
  23.  
  24.     return runTime;
  25.  
  26. end
  27.  
  28. function MeasureTimeBelapsed( mX )
  29.  
  30.     runTime = @belapsed SimpleMatrixOperation(mX);
  31.  
  32.     return runTime;
  33.  
  34. end
  35.  
  36. matrixSize = 500;
  37. numIterations = 7;
  38.  
  39. mX = randn(matrixSize, matrixSize);
  40.  
  41. runTimeA = MeasureTimeIterations(mX, numIterations);
  42. runTimeB = MeasureTimeIterations(mX, 10 * numIterations);
  43. runTimeC = MeasureTimeBtime(mX);
  44. @btime SimpleMatrixOperation($mX)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement