Macros not working as expected

Hi everyone,

I’ve just started using Julia and was trying to understand how macros work. I ran two simple tests with the macros devec and parallel and it seems to be getting slower instead of faster. Here are the two simple tests I ran:

First, with @devec:

a = ones(10)
b = ones(10)*5
tic()
@devec c = a.*b
toc()

elapsed time: 0.016007498 seconds

as opposed to

tic()
a.*b
toc()

elapsed time: 0.00013638 seconds.

Similarly,

a = ones(10000)*0.5
tic()
sumOfSquares = @parallel (+) for i in 1:10000
a[i]^2
end
toc()

elapsed time: 0.04703732 seconds

whereas not using the macro with the following code:

tic()
sumOfSquares = 0
for i in 1:10000
sumOfSquares += a[i]^2
end
toc()
elapsed time: 0.007251497 seconds.

Don’t benchmark in global scope (see performance tips).

@devec is deprecated. Use dot fusion instead: More Dots: Syntactic Loop Fusion in Julia

1 Like

Thank you! That makes sense now.