Topic
1 reply Latest Post - ‏2012-11-08T17:58:51Z by SystemAdmin
SystemAdmin
SystemAdmin
196 Posts
ACCEPTED ANSWER

Pinned topic Performance problem after call to localtime - AIX6.1, XL C/C++ 11.1

‏2012-11-02T14:18:52Z |
Hi

We are experiencing performance problems with a C++ program that we cannot explain. The example below shows the problem. A loop assigns a value to a string 3 million times - this starts off taking about 1s. Between calls to this loop we make a call to the localtime function, after the call the string assignment loop takes 10-20 times longer.

Calls to localtime, ctime and to the boost local_time functions give this performance degradation, but calls to gmtime do not.

Can anyone help explain why this is happening!
#include <iostream>
#include <string>
#include <time.h>
//#include "boost/date_time/posix_time/posix_time.hpp"

using namespace std;
//using namespace boost::posix_time;

std::string doLoop()
{
cout << "LOOP START" << endl;
system("date");

string s;
int i;
for (i=0; i < 30000000 ; i++)
{
s="XXXX";
}
cout << "Looped " << i << " times." << endl;

cout << "LOOP END" << endl;
system("date");

cout << endl;

return s;
}
int main()
{
// This loop runs quickly
doLoop();

// Still quick
doLoop();

// Now as soon as we call ctime or localtime (uncomment any one of these to test) we see the issue
//cout << "Return value from ctime:" << ctime(NULL) << endl;
cout << "Calling localtime:" << endl; localtime(NULL);

// We also get the same performance problem using boost date/times (uncomment the boost headers and using statements above to test)
//ptime now = second_clock::local_time();

// NB) calls to gmtime do not cause a problem!
//cout << "Calling gmtime:" << endl; time_ptr=gmtime(&seconds);

// Any loop we do after a these operations takes much longer
doLoop();

doLoop();

}

This is the output we get:
LOOP START
Fri Nov 2 13:47:48 GMT 2012
Looped 30000000 times.
LOOP END
Fri Nov 2 13:47:49 GMT 2012

LOOP START
Fri Nov 2 13:47:49 GMT 2012
Looped 30000000 times.
LOOP END
Fri Nov 2 13:47:50 GMT 2012

Calling localtime:
LOOP START
Fri Nov 2 13:47:50 GMT 2012
Looped 30000000 times.
LOOP END
Fri Nov 2 13:48:14 GMT 2012

LOOP START
Fri Nov 2 13:48:14 GMT 2012
Looped 30000000 times.
LOOP END
Fri Nov 2 13:48:36 GMT 2012
Updated on 2012-11-08T17:58:51Z at 2012-11-08T17:58:51Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    196 Posts
    ACCEPTED ANSWER

    Re: Performance problem after call to localtime - AIX6.1, XL C/C++ 11.1

    ‏2012-11-08T17:58:51Z  in response to SystemAdmin
    Just in case anyone else comes across a similar problem and is afraid to post in case they get a similarly overwhelming response, this is what we have found out....

    From AIX 6.1 onwards the default value of the TZ environment variable uses an Olson format time-zone setting (whereas previous versions use POSIX format). Additionally there is a performance issue with using the Olson database for timezone calculations on AIX 6.1

    So, we resolved our performance problem by setting the TZ environment variable back to a POSIX format timezone string. An alternative solution would have been to upgrade to AIX 7.1 as apparently the problem is resolved in this OS version, even for Olson format time-zone strings.

    This APAR vaguely touches on the problem....

    http://www-01.ibm.com/support/docview.wss?uid=isg1IZ86764