Home > database >  I want to obtain the ASM (Intel assembly) code generated by Julia
I want to obtain the ASM (Intel assembly) code generated by Julia

Time:01-23

I wrote a simple for loop in Delphi and translated it to Julia. The execution time of the Delphi program, compared with the Julia one, is just pathetic: Julia is 7 times faster - see the program and the results.

I am trying to figure out how this is possible, because Delphi was supposed to be one of the fastest languages on the planet!

I want to compare the ASM code generated by Julia with the ASM code generated by Delphi. In Delphi, I need only one click to get that code. Where I can see the ASM code for a specific function in Julia?

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)

CodePudding user response:

You use the @code_native macro applied to the function call. Here's an example

julia> @code_native 1 1
        .text
        .file   " "
        .globl  "julia_ _13305"                 # -- Begin function julia_ _13305
        .p2align        4, 0x90
        .type   "julia_ _13305",@function
"julia_ _13305":                        # @"julia_ _13305"
; ┌ @ int.jl:87 within ` `
        .cfi_startproc
#            
  • Related