[MOAB-dev] Discussion on return type of MOAB routines

Wu, Danqing wuda at mcs.anl.gov
Fri Jan 24 11:50:21 CST 2014


Even with C style struct, without explicitly defined constructors, there is still noticeable difference.

Used g++ -O3 to build.
For returning plain enum type, the result on my laptop is
real	0m0.003s
user	0m0.000s
sys	0m0.000s

For returning struct, the result is
real	0m4.114s
user	0m4.112s
sys	0m0.000s

//////////////////////////////////////////////
#include <iostream>

using namespace std;

enum ErrorCode { MB_SUCCESS = 0, MB_FAILURE = 1 };

struct ErrorInfo {
  ErrorCode mErrorCode;
};

ErrorCode test_return_0(long n)
{
  if (n > 0)
    return test_return_0(n - 1);

  return MB_SUCCESS;
}

ErrorInfo test_return_1(long n)
{
  if (n > 0)
    return test_return_1(n - 1);

  return ErrorInfo();
}

int main()
{
  for (long i = 0; i < 100000; i++)
    test_return_0(100000); // Change to test_return_1(100000) for comparison

  return 0;
}
________________________________________
From: Jed Brown [jed at jedbrown.org]
Sent: Friday, January 24, 2014 11:30 AM
To: Tautges, Timothy J.; Vijay S. Mahadevan
Cc: Wu, Danqing; Paul Wilson; moab-dev at mcs.anl.gov
Subject: Re: [MOAB-dev] Discussion on return type of MOAB routines

"Tim Tautges (ANL)" <tautges at mcs.anl.gov> writes:

> Yeah, but even the ErrorCode-only class version was way slower than
> the one returning only ErrorCode, that's what makes me think there's
> C++ stuff going on behind the scenes (or optimizations the class
> version doesn't get) that is causing the big jump.

Where is the exact code?  Also, it should be obvious in the assembly.


More information about the moab-dev mailing list