【发布时间】:2021-12-31 17:54:54
【问题描述】:
我有以下 MATLAB sn-p:
>> R = randn(3000,6000); % build a random 3000 by 6000 matrix
>> tic; norm(R, 1); toc;
Elapsed time is 0.005586 seconds.
>> tic; norm(R, 2); toc;
Elapsed time is 3.019667 seconds.
>> tic; norm(R, inf); toc;
Elapsed time is 0.005393 seconds.
>>
我的问题是,为什么 L2 范数计算会比 L1 或 L 无穷范数慢得多?当然,这是一个用于测试目的的随机矩阵,但对于我工作中的实际矩阵,我可以在经过的时间方面看到类似的模式。
但是,在Julia上,结果如下
julia> @time norm(R, 1);
0.007156 seconds (1 allocation: 16 bytes)
julia> @time norm(R, 2);
0.009142 seconds (1 allocation: 16 bytes)
julia> @time norm(R, Inf);
0.034633 seconds (1 allocation: 16 bytes)
这根本没有意义。任何帮助表示赞赏!
【问题讨论】:
-
请注意,在 Julia 中,最好使用
BenchmarkTools.jl中的@btime进行计时,以确保不会意外捕获编译时间。
标签: performance matlab matrix julia linear-algebra