我想获取Julia生成的ASM(Intel汇编)代码

WeG*_*ars 4 delphi execution-time compiler-optimization julia

for在 Delphi 中编写了一个简单的循环并将其翻译为 Julia。与 Julia 程序相比,Delphi 程序的执行时间简直可怜:Julia 快了 7 倍 -查看程序和结果

我试图弄清楚这是如何可能的,因为 Delphi 应该是地球上最快的语言之一!

我想将 Julia 生成的 ASM 代码与 Delphi 生成的 ASM 代码进行比较。在 Delphi 中,我只需单击一下即可获取该代码。在哪里可以看到 Julia 中特定函数的 ASM 代码?

using BenchmarkTools
println("----------- Test for loops")
# test for loops
function for_fun(a)
    total = 0
    big = 0
    small = 0
    for i in 1:a
        total += 1
        if i > 500000
            big += 1
        else
            small += 1
        end    
    end   

    return (total, small, big)
end

res_for = for_fun(1000000000)
println(res_for)
@btime for_fun(1000000000)
Run Code Online (Sandbox Code Playgroud)

Fre*_*gge 5

您使用@code_native应用于函数调用的宏。这是一个例子

\n
julia> @code_native 1+1\n        .text\n        .file   "+"\n        .globl  "julia_+_13305"                 # -- Begin function julia_+_13305\n        .p2align        4, 0x90\n        .type   "julia_+_13305",@function\n"julia_+_13305":                        # @"julia_+_13305"\n; \xe2\x94\x8c @ int.jl:87 within `+`\n        .cfi_startproc\n# %bb.0:                                # %top\n        leaq    (%rdi,%rsi), %rax\n        retq\n.Lfunc_end0:\n        .size   "julia_+_13305", .Lfunc_end0-"julia_+_13305"\n        .cfi_endproc\n; \xe2\x94\x94\n                                        # -- End function\n        .section        ".note.GNU-stack","",@progbits\n
Run Code Online (Sandbox Code Playgroud)\n