Thursday, June 13, 2024
HomeGolangNested C Features - Getting Assist

Nested C Features – Getting Assist


Hiya, can somebody inform me why the next code :

bundle important
/*
lengthy Add ( lengthy a, lengthy b ) {

    return a + b ;

}

lengthy caller2 ( lengthy a, lengthy b ) {

    return Add(a,b);

}

lengthy caller (  ) {

    lengthy numAdd = 1 ;
    lengthy i ;
    for ( i = 1 ; i <= 10000000000 ; i++ ) {

        numAdd = caller2 ( numAdd, i ) ;

    }
    
    return numAdd ;

}
*/
import "C"
import ( "fmt"; "time" )
func important (  ) {

    var timeBefore = time.Now ( ) ;
    ///////////////////////////////
    var checkNumber C.lengthy = C.caller( ) ;
    //////////////////////////////
    var timeAfter = time.Now ( ) ;
    fmt.Println ( checkNumber ) ;
    fmt.Println ( timeAfter.Sub(timeBefore) ) ;

}

Is so mush slower than :

bundle important
/*
lengthy caller (  ) {


    lengthy Add ( lengthy a, lengthy b ) { // nested perform

        return a + b ;

    }


    lengthy caller2 ( lengthy a, lengthy b ) { // nested perform

        return Add(a,b);

    }


    lengthy numAdd = 1 ;
    lengthy i ;
    for ( i = 1 ; i <= 10000000000 ; i++ ) {

        numAdd = caller2 ( numAdd, i ) ;

    }
    
    return numAdd ;

}
*/
import "C"
import ( "fmt"; "time" )
func important (  ) {

    var timeBefore = time.Now ( ) ;
    ///////////////////////////////
    var checkNumber C.lengthy = C.caller( ) ;
    //////////////////////////////
    var timeAfter = time.Now ( ) ;
    fmt.Println ( checkNumber ) ;
    fmt.Println ( timeAfter.Sub(timeBefore) ) ;

}

End result :

The primary : 32.184687445s
The second : 6.873829046s

Does nested C features case somewhat overhead in comparison with top-level features?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments