julialogic

In julia, which is more performant a >= b && c <= b vs !(a<b || c>b)


a >= b && c <= b vs !( a < b || c > b)

Which is more performant in julia?


Solution

  • In my case the generated codes are identically.

    @code_native ((a,b,c)->a >= b && c <= b)(1,2,3)
    
            .text
            .file   "#1"
            .globl  "julia_#1_61"                   # -- Begin function julia_#1_61
            .p2align        4, 0x90
            .type   "julia_#1_61",@function
    "julia_#1_61":                          # @"julia_#1_61"
    ; ┌ @ REPL[1]:1 within `#1`
    # %bb.0:                                # %top
            push    rbp
            mov     rbp, rsp
    ; │┌ @ operators.jl:425 within `>=`
    ; ││┌ @ int.jl:514 within `<=`
            cmp     rsi, rdi
            setle   cl
    ; │└└
            cmp     rdx, rsi
            setle   al
            and     al, cl
    ; │┌ @ int.jl:514 within `<=`
            pop     rbp
            ret
    .Lfunc_end0:
            .size   "julia_#1_61", .Lfunc_end0-"julia_#1_61"
    ; └└
                                            # -- End function
            .section        ".note.GNU-stack","",@progbits
    
    @code_native ((a,b,c)->!( a < b || c > b))(1,2,3)
    
            .text
            .file   "#3"
            .globl  "julia_#3_87"                   # -- Begin function julia_#3_87
            .p2align        4, 0x90
            .type   "julia_#3_87",@function
    "julia_#3_87":                          # @"julia_#3_87"
    ; ┌ @ REPL[2]:1 within `#3`
    # %bb.0:                                # %top
            push    rbp
            mov     rbp, rsp
    ; │┌ @ int.jl:83 within `<`
            cmp     rdi, rsi
            setge   cl
    ; │└
            cmp     rsi, rdx
            setge   al
            and     al, cl
    ; │┌ @ bool.jl:35 within `!`
            pop     rbp
            ret
    .Lfunc_end0:
            .size   "julia_#3_87", .Lfunc_end0-"julia_#3_87"
    ; └└
                                            # -- End function
            .section        ".note.GNU-stack","",@progbits
    
    @code_native ((a, b, c) -> c <= b <= a)(1, 2, 3)
    
            .text
            .file   "#1"
            .globl  "julia_#1_61"                   # -- Begin function julia_#1_61
            .p2align        4, 0x90
            .type   "julia_#1_61",@function
    "julia_#1_61":                          # @"julia_#1_61"
    ; ┌ @ REPL[1]:1 within `#1`
    # %bb.0:                                # %top
            push    rbp
            mov     rbp, rsp
    ; │┌ @ int.jl:514 within `<=`
            cmp     rdx, rsi
            setle   cl
    ; │└
            cmp     rsi, rdi
            setle   al
            and     al, cl
    ; │┌ @ int.jl:514 within `<=`
            pop     rbp
            ret
    .Lfunc_end0:
            .size   "julia_#1_61", .Lfunc_end0-"julia_#1_61"
    ; └└
                                            # -- End function
            .section        ".note.GNU-stack","",@progbits