Is calling a nested function faster or not?

I have this stupid argument with a friend and he needs an authoritative word.

I have these two snippets and want to know which one is faster? [A or B]

(assuming the compiler is not optimizing anything)

[A]

if ( foo () ); 

[AT]

int t = foo ();
if ( t )

EDIT . Guys, this may seem like a silly question for you, but I have an engineer-engineer-engineer who claimed that even WITHOUT optimization (take any processor, any pair of compiler) CASE B is always faster because it does NOT retrieve memory for the result from of the previous instruction, but directly receives the result from the common data bus, bypassing this data (remember the 5-stage pipeline).

My Argument , , , , ( , , , )

+3
6

gcc (-O0) ( foo return rand();, ).

t:

        movl    $0, %eax
        call    foo
        testl   %eax, %eax
        je      .L4
        /* inside of if block */
.L4:
        /* rest of main() */

foo EAX, , , 0, , if.

t:

        movl    $0, %eax
        call    foo
        movl    %eax, -4(%rbp)
        cmpl    $0, -4(%rbp)
        je      .L4
        /* inside of if block */
.L4:
        /* rest of main() */

foo EAX, . 0, , if.

, , "", , . , , L1, , .

, , , -O1, , , ?

: -, , L1 , . , , , , , movl . , ; , C.

+3

"", [B] [A], ( t ), , , . -, , , , .

- , .

+13


1. . 30 . 2. , , [A]


: [B]
foo int, , int, bool, . Sleep.

, int:


" " , . B 10 , ( , , ).


, , .

x86/x64:

miniscule
  t , 2 (, ). " " - foo, foo . 20.200 .

: , 1- (: 100 2- , 1000 , )

...
, . - / .

+4

, , . int .

+2

, . , A . :

B , t, if. .

0

A, , - , . , , , .

-1

Source: https://habr.com/ru/post/1742631/


All Articles