# Meta programming on fuction definning

**URL:** <https://discourse.julialang.org/t/meta-programming-on-fuction-definning/88826>\
**Category:** New to Julia\
**Created:** [October 17, 2022, 6:27am UTC](https://discourse.julialang.org/t/meta-programming-on-fuction-definning/88826 "2022-10-17T06:27:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brian1/32/49250_2.png) [@Brian1](https://discourse.julialang.org/u/Brian1)\
**Post date:** [October 17, 2022, 6:27am UTC](https://discourse.julialang.org/t/meta-programming-on-fuction-definning/88826/1 "2022-10-17T06:27:48Z")

</div>

There is a function:

```julia
function fun(x)
    a = x + 1
    b = x + 2
    return a + b
end

```

Is there a way I can do this?

```julia
@custom_macro function fun(x)
    a = x + 1
    b = x + 2
    return a + b
end

```

So the function `fun` is actually:

```julia
function fun(x)
    @time "line1" a = x + 1
    @time "line2" b = x + 2
    return a + b
end

```

Or is there a way I can do this?

```julia
function fun(x)
    a = x + 1
    b = x + 2
    return a + b
end

#when I run 
@custom_macro fun(10)
#It is actually running:
function fun(x)
    @time "line1" a = x + 1
    @time "line2" b = x + 2
    return a + b
end

```

---

<div class="post-metadata">

**Author:** ![Jollywatt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jollywatt/32/202198_2.png) [@Jollywatt](https://discourse.julialang.org/u/Jollywatt)\
**Post date:** [October 17, 2022, 7:00am UTC](https://discourse.julialang.org/t/meta-programming-on-fuction-definning/88826/2 "2022-10-17T07:00:47Z")

</div>

I’m not answering your question, but it looks like you want to get an idea of how different parts of an arbitrary function consume runtime. If that’s the case, check out [profiling in Julia](https://docs.julialang.org/en/v1/manual/profile/).

---

<div class="post-metadata">

**Author:** ![Brian1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brian1/32/49250_2.png) [@Brian1](https://discourse.julialang.org/u/Brian1)\
**Post date:** [October 17, 2022, 7:02am UTC](https://discourse.julialang.org/t/meta-programming-on-fuction-definning/88826/3 "2022-10-17T07:02:38Z")

</div>

I find a way:

```julia
macro time_each_line(x)
    args = x.args[2].args
    for i = 1 : size(args, 1)
        args[i] isa Expr || continue
        args[i] = :(@time $i $(args[i]))
    end
    quote 
        $x 
    end |> esc
end

```

But it is too messy. Any more elegant way ?
