inlining static members in cpp?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

inlining static members in cpp?

Alex Liebert
I was cleaning up some code that's checking Ints and was wondering if the following will incur any performance penalty (on cpp):

class MySize
{
public static inline var SMALL:Int=1;
}

/**
* in another class
*/
// is this...
if (size == MySize.SMALL)

// more performant than this...?
if (size==1)


Does the class look up matter?

Thanks!

Alex


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: inlining static members in cpp?

Tony Polinelli
If you look at the generated CPP code - you should see that the inlineing makes it

if (((size == (int)1))){

which is that same as typing in the Int. So the performance should be the same i'd think

On Wed, Nov 30, 2011 at 4:59 AM, Alex Liebert <[hidden email]> wrote:
I was cleaning up some code that's checking Ints and was wondering if the following will incur any performance penalty (on cpp):

class MySize
{
public static inline var SMALL:Int=1;
}

/**
* in another class
*/
// is this...
if (size == MySize.SMALL)

// more performant than this...?
if (size==1)


Does the class look up matter?

Thanks!

Alex


--
haXe - an open source web programming language
http://haxe.org



--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: inlining static members in cpp?

Alex Liebert
thanks tony!

On Tue, Nov 29, 2011 at 10:01 PM, Tony Polinelli <[hidden email]> wrote:
If you look at the generated CPP code - you should see that the inlineing makes it

if (((size == (int)1))){

which is that same as typing in the Int. So the performance should be the same i'd think

On Wed, Nov 30, 2011 at 4:59 AM, Alex Liebert <[hidden email]> wrote:
I was cleaning up some code that's checking Ints and was wondering if the following will incur any performance penalty (on cpp):

class MySize
{
public static inline var SMALL:Int=1;
}

/**
* in another class
*/
// is this...
if (size == MySize.SMALL)

// more performant than this...?
if (size==1)


Does the class look up matter?

Thanks!

Alex


--
haXe - an open source web programming language
http://haxe.org



--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org