# Comparing Julia functions

**URL:** <https://discourse.julialang.org/t/comparing-julia-functions/82990>\
**Category:** General Usage\
**Tags:** question, functions\
**Created:** [June 19, 2022, 12:41am UTC](https://discourse.julialang.org/t/comparing-julia-functions/82990 "2022-06-19T00:41:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![math\_opt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/math_opt/32/25317_2.png) [@math\_opt](https://discourse.julialang.org/u/math_opt)\
**Post date:** [June 19, 2022, 12:41am UTC](https://discourse.julialang.org/t/comparing-julia-functions/82990/1 "2022-06-19T00:41:05Z")

</div>

Is there a way to view the lower level code of a Julia function? I want to confirm whether the two functions are equivalent. For example:

```julia
function modify1(a,b)
    return a+b
end

function modify2(a,b)
    return (a+b)*(a-b)
end

function modify3(a,b)
    return modify1(a,b)*(a-b)
end

```

Now, I know `modify2` and `modify3` are equivalent; however, I want to see the lower-level code to make sure that is indeed the case (I have more complex functions that I want to compare). Is there a way to do so with or without looking at the lower-level code except by testing the functions for different input values?

---

<div class="post-metadata">

**Author:** ![dylanxyz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dylanxyz/32/36646_2.png) [@dylanxyz](https://discourse.julialang.org/u/dylanxyz)\
**Post date:** [June 19, 2022, 12:58am UTC](https://discourse.julialang.org/t/comparing-julia-functions/82990/2 "2022-06-19T00:58:22Z")

</div>

You can use `@code_lowered` to inspect the lowered code of a function, for example:

```julia
julia> @code_lowered modify1(1, 2)
CodeInfo(
1 ─ %1 = a + b
└── return %1
)

julia> @code_lowered modify2(1, 2)
CodeInfo(
1 ─ %1 = a + b
│ %2 = a - b
│ %3 = %1 * %2
└── return %3
)

julia> @code_lowered modify3(1, 2)
CodeInfo(
1 ─ %1 = Main.modify1(a, b)
│ %2 = a - b
│ %3 = %1 * %2
└── return %3
)

```

You can also use `@code_native` to inspect the actual assembly instructions:

```julia
julia> @code_native debuginfo=:none modify1(1, 2)
        .text
        pushq %rbp
        movq %rsp, %rbp
        leaq (%rcx,%rdx), %rax
        popq %rbp
        retq
        nopw (%rax,%rax)

julia> @code_native debuginfo=:none modify2(1, 2)
        .text
        pushq %rbp
        movq %rsp, %rbp
        leaq (%rdx,%rcx), %rax
        subq %rdx, %rcx
        imulq %rcx, %rax
        popq %rbp
        retq
        nopw %cs:(%rax,%rax)

julia> @code_native debuginfo=:none modify3(1, 2)
        .text
        pushq %rbp
        movq %rsp, %rbp
        leaq (%rdx,%rcx), %rax
        subq %rdx, %rcx
        imulq %rcx, %rax
        popq %rbp
        retq
        nopw %cs:(%rax,%rax)

```

---

<div class="post-metadata">

**Author:** ![math\_opt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/math_opt/32/25317_2.png) [@math\_opt](https://discourse.julialang.org/u/math_opt)\
**Post date:** [June 19, 2022, 4:45am UTC](https://discourse.julialang.org/t/comparing-julia-functions/82990/3 "2022-06-19T04:45:18Z")

</div>

That’s helpful. Thanks!
