[Kst] branches/work/kst/portto4/kst/src/libkst
Peter Kümmel
syntheticpp at gmx.net
Thu Oct 18 14:02:11 UTC 2012
SVN commit 1321285 by kuemmel:
remove unused timing code
M +19 -33 measuretime.cpp
M +3 -13 measuretime.h
--- branches/work/kst/portto4/kst/src/libkst/measuretime.cpp #1321284:1321285
@@ -14,40 +14,30 @@
#include "debug.h"
-#ifdef Q_OS_WIN
-#include <windows.h>
-#else
+#include <iostream>
#include <time.h>
-#endif
-#include <iostream>
-MeasureTime::MeasureTime(const QString& n) :
- started(0),
- interval(0),
- name(n),
- other_interval(0)
+#ifdef Q_OS_WIN
+#include <windows.h>
+static qint64 largeIntToInt64(const LARGE_INTEGER& i)
{
- setFrequency();
- restart();
+ return ((qint64)i.HighPart) << 32 | i.LowPart;
}
-
-
-void MeasureTime::setFrequency()
+static double readFrequency()
{
-#ifdef Q_OS_WIN
- LARGE_INTEGER proc_freq;
- QueryPerformanceFrequency(&proc_freq);
- frequency = 1.0 / proc_freq.QuadPart;
-#endif
+ LARGE_INTEGER largeInt;
+ if (!QueryPerformanceFrequency(&largeInt))
+ return 0;
+ return 1.0 / largeIntToInt64(largeInt);
}
+static double frequency = readFrequency();
+#endif
-MeasureTime::MeasureTime(MeasureTime& rhs) :
+MeasureTime::MeasureTime(const QString& n) :
started(0),
- interval(0),
- frequency(rhs.frequency),
- other_interval(&rhs.interval)
+ name(n)
{
restart();
}
@@ -55,22 +45,18 @@
MeasureTime::~MeasureTime()
{
- if (other_interval) {
- measure();
- *other_interval += interval;
- } else {
print();
}
-}
double MeasureTime::getTime() const
{
#ifdef Q_OS_WIN
- LARGE_INTEGER st;
- QueryPerformanceCounter(&st);
- return st.QuadPart * frequency;
+ LARGE_INTEGER largeInt;
+ if (!QueryPerformanceCounter(&largeInt))
+ return 0;
+ return largeIntToInt64(largeInt) * frequency;
#else
@@ -112,7 +98,7 @@
void MeasureTime::print()
{
measure();
- //qDebug() << "MeasureTime in " << name << ": " << interval << " seconds\n";
+ qWarning(qPrintable(QString("MeasureTime in %1: %2 sec").arg(name ).arg(interval)));
Kst::Debug::self()->log(QString("Timing: %2 sec, Scope: %1").arg(name).arg(interval), Kst::Debug::DebugLog);
}
--- branches/work/kst/portto4/kst/src/libkst/measuretime.h #1321284:1321285
@@ -22,32 +22,22 @@
{
public:
MeasureTime(const QString& name);
-
- /// Init with other instance to increment parent's interval in detor
- /// Needed to sum over multiple measurements.
- MeasureTime(MeasureTime& parent);
~MeasureTime();
- void restart();;
+ void restart();
/// print interval to console
void print();
- private:
+ double getTime() const;
+ private:
double started;
double interval;
- double frequency;
QString name;
- double* other_interval;
-
- void setFrequency();
-
/// Increment interval by interval since last call/restart().
void measure();
-
- double getTime() const;
};
#define TIME_IN_SCOPE(x) MeasureTime x(QString("%1 at %2, line %3, time in scope").arg(#x).arg(__FILE__).arg(__LINE__))
More information about the Kst
mailing list