I need to generate a Hadamard matrix with dimensions of $4096$, but it seems Mathematica is much slower than MATLAB when generating such matrices.
This program
(MatrixPlot @ HadamardMatrix[4096]) // AbsoluteTiming
cost about 36 seconds on my computer to finish. While for MATLAB,
H = hadamard(4096); imshow(H)
cost about 0.7 seconds.
I tested the pure process of generating the H
matrix. The code is listed below.
Mathematica cost 20 seconds:
HadamardMatrix[4096, WorkingPrecision -> MachinePrecision] // AbsoluteTiming
MATLAB cost 0.12 second:
hadamard(4096)
I was wondering if there is any method to increase the speed or efficiency of Mathematica on this problem?
Jim has provided a way of changing the Method:
HadamardMatrix[4096, Method -> "BitComplement"] // AbsoluteTiming
HadamardMatrix[4096, Method -> "Sequency"] // AbsoluteTiming
It improves the speed a little bit, but still much slower than MATLAB
HadamardMatrix[4096, WorkingPrecision -> MachinePrecision]
alter the timing significantly? (I’m on mobile and can’t test it myself). $\endgroup$ – MarcoB Jun 28 '18 at 3:19Method->"BitComplement"
andMethod->"Sequency"
. The former is much faster. Which does Matlab produce? $\endgroup$ – JimB Jun 28 '18 at 3:23