// ********** SingletonDemo.cpp ********** #include #include using namespace std; class Singleton { private: static Singleton* instance; int value; Singleton() { value = 0; } public: static Singleton* getInstance() { if (!instance) instance = new Singleton(); return instance; } int getValue() { return value; } void setValue(int i) { value = i; } }; Singleton* Singleton::instance = 0; const int MAX = 50000000; int main() { hrtime_t t1 = gethrtime(); for (int i=0; isetValue(i); hrtime_t t2 = gethrtime(); cout << (t2-t1)/1000000 << " "; return 1; }