# Macros not working as expected

**URL:** <https://discourse.julialang.org/t/macros-not-working-as-expected/3753>\
**Category:** General Usage\
**Created:** [May 16, 2017, 8:19pm UTC](https://discourse.julialang.org/t/macros-not-working-as-expected/3753 "2017-05-16T20:19:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anirudh\_Krishna](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Anirudh\_Krishna](https://discourse.julialang.org/u/Anirudh_Krishna)\
**Post date:** [May 16, 2017, 8:19pm UTC](https://discourse.julialang.org/t/macros-not-working-as-expected/3753/1 "2017-05-16T20:19:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [May 16, 2017, 8:20pm UTC](https://discourse.julialang.org/t/macros-not-working-as-expected/3753/2 "2017-05-16T20:20:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [May 16, 2017, 8:21pm UTC](https://discourse.julialang.org/t/macros-not-working-as-expected/3753/3 "2017-05-16T20:21:15Z")

</div>

`@devec` is deprecated. Use dot fusion instead: [More Dots: Syntactic Loop Fusion in Julia](https://julialang.org/blog/2017/01/moredots)

---

<div class="post-metadata">

**Author:** ![Anirudh\_Krishna](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Anirudh\_Krishna](https://discourse.julialang.org/u/Anirudh_Krishna)\
**Post date:** [May 17, 2017, 3:24am UTC](https://discourse.julialang.org/t/macros-not-working-as-expected/3753/4 "2017-05-17T03:24:24Z")

</div>

Thank you! That makes sense now.
