The following link: Trying to understand memory usage
If I do this (see link above) on my Macbook 13" with M1 processor and 8GB RAM and SSD (Julia Rosetta Version 1.7.1 (2021-12-22)):
julia> using LinearAlgebra
julia> using BenchmarkTools
julia> function func1()
a = rand(100,1000)
return norm(a,2)
end
julia> @benchmark begin
for i in 1:10000
func1()
end
end
BenchmarkTools.Trial: 1 sample with 1 evaluation.
Single result which took 92.445 s (0.04% GC) to evaluate,
with a memory estimate of 7.45 GiB, over 20000 allocations.
Something is not right here. A runtime of 92 seconds (the poster in the original thread, see link above, had it back in 4 seconds).
My Python version takes (time python test.py): 5.41s user 0.05s system 99% cpu 5.493 total
Even if Python does not (which I donβt know just speculation) copy a new array every time it advances func1() in the loop there is no reason why Julia is so slow (note: I havenβt checked if python does the same as the Julia code 1-based indexing):
import numpy as np
def func1():
a = np.random.rand(100,1000)
#return np.linalg.norm(a, axis=0)
return np.linalg.norm(a, axis=1)
def benchmark():
for i in range(0,10000):
tmp = func1()
#print statement wonβt make a difference in terms of timing
#print('i ', i, np.sum(tmp))
return βokayβ
print(benchmark())
Edit: My Python is Python 3.8.12, [Clang 10.0.0 ] :: Anaconda, Inc. on darwin