atof is dead slow on Windows, on Linux atof is magnitudes faster.
Measured with attached patch.
Peter
Brisset, Nicolas wrote:
> Hi,
>
>
>
> being an avid KDE user and working in a very Windows-centric
> organization, I'm very interested by the potential of KDE (and Qt) tools
> running under Windows. One of the projects I'm most actively involved in
> (mainly as a tester and bug reporter, though I occasionally contributed
> some code as well) is kst, a great (though not so well known)
> professional plotting tool.
>
> I've just subscribed to this list to be able to follow progress on the
> KDE Windows front, and also to be able to get some advice on kst under
> Windows, as version 2.0.0 (due soon) will be the first to run on that
> platform. We are currently testing it and there are a few things we are
> a bit puzzled at. If anybody could give some advice, we'd be very grateful.
>
> The 2 biggest problems we have so far are a memleak (I'll send another
> message with information on that one) and a performance problem detailed
> in the message below, which I am forwarding as it seems it did not make
> it to the list.
>
> You can find kst code under
> https://[[email protected]/home/kde/branches/work/kst/portto4/kst
> <https://%[email protected]/home/kde/branches/work/kst/portto4/kst>
> (of course also available with anonymous svn, though not from behind a
> proxy…), as far as I know it currently requires any Qt 4 version (not
> necessarily the latest).
>
>
>
> Kst 1.x was a KDE application, but kst 2.x is so far pure Qt (.pro
> based), though an optional KDE integration is planned down the road. I
> hope that still qualifies it to be discussed on this list J
>
>
>
> Don't hesitate to ask for more information if needed,
>
> Best regards,
>
>
>
> Nicolas
>
>
>
> ------------------------------------------------------------------------
>
> *Von:* Brisset, Nicolas
> *Gesendet:* Donnerstag, 12. November 2009 17:11
> *An:* '[email protected]'; '[email protected]'
> *Betreff:* Huge performance problem under Windows
>
>
>
> Hi,
>
>
>
> I had used kst windows so far on fairly small files. I had the
> impression it was slower than the Linux version but it was only
> subjective. I tried to load gyrodata.dat from the SVN repos today to
> show off the performance to a colleague. Well, it turns out it was a bad
> idea L: it takes **ages** to load (I'm talking about minutes here, don't
> discourage it will eventually appear !). I have no idea where the
> difference comes from, loading the same file under Linux with the same
> version (svn HEAD) is **instantaneous**.
>
> Maybe the KDE-Windows folks could help there? There must be a stupid
> reason. I tried the kst 2.0.0 beta from the website (I believe it was
> compiled with VC++) and todays's SVN compiled qith Qt SDK (Creator)
> 2009.02. This is to me a blocking point for widespread use on Windows…
>
>
>
> Nicolas
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Kde-windows mailing list
> [email protected]
> https://mail.kde.org/mailman/listinfo/kde-windows
Index: src/datasources/ascii/ascii.cpp
===================================================================
--- src/datasources/ascii/ascii.cpp (revision 1049047)
+++ src/datasources/ascii/ascii.cpp (working copy)
@@ -15,7 +15,6 @@
* *
***************************************************************************/
-
#include <assert.h>
#include <ctype.h>
#include <math.h>
@@ -40,6 +39,10 @@
#include "ui_asciiconfig.h"
#include "kst_i18n.h"
+#ifdef Q_CC_MSVC
+#include <windows.h>
+#endif
+
#define DEFAULT_DELIMITERS "#/c!;"
#define DEFAULT_COLUMN_WIDTH 16
@@ -371,7 +374,8 @@
}
} while (bufread == MAXBUFREADLEN);
- free(del);
+ // TODO crash o windows
+ // free(del);
file.close();
@@ -402,7 +406,77 @@
}
+struct MeasureTime
+{
+ MeasureTime(const QString& n) : sum(0), name(n), other_sum(0)
+ {
+ setFrequency();
+ }
+ void setFrequency()
+ {
+#ifdef Q_CC_MSVC
+ LARGE_INTEGER proc_freq;
+ QueryPerformanceFrequency(&proc_freq);
+ frequency = 1.0 / proc_freq.QuadPart;
+#else
+#endif
+ }
+
+ MeasureTime(MeasureTime& rhs) : sum(0), frequency(rhs.frequency),
other_sum(&rhs.sum)
+ {
+ start();
+ }
+
+ ~MeasureTime()
+ {
+ add();
+ if (other_sum)
+ *other_sum += sum;
+ }
+
+ void start()
+ {
+#ifdef Q_CC_MSVC
+ QueryPerformanceCounter(&started);
+#else
+ started = clock();
+#endif
+ }
+
+ void add()
+ {
+#ifdef Q_CC_MSVC
+ LARGE_INTEGER now;
+ QueryPerformanceCounter(&now);
+ sum += 1.0 * (now.QuadPart -started.QuadPart) * frequency;
+#else
+ int now = clock();
+ sum += 1.0 * (now - started) / CLOCKS_PER_SEC;
+#endif
+ }
+
+ void print()
+ {
+ printf("%s: sum = %f\n", qPrintable(name), sum);
+ }
+
+#ifdef Q_CC_MSVC
+ LARGE_INTEGER started;
+#else
+ int started;
+#endif
+ double sum;
+ double frequency;
+ QString name;
+
+ double* other_sum;
+};
+
+typedef MeasureTime M;
+
+
+
int AsciiSource::readField(double *v, const QString& field, int s, int n) {
if (n < 0) {
n = 1; /* n < 0 means read one sample, not frame - irrelevent here */
@@ -493,30 +567,64 @@
}
}
} else {
+
+ M ms("isspace");
+ M mc("config");
+ M md("isdigit");
+ M ma("atof");
+ M ml("tolower");
+ int mi = 0;
+
for (int i = 0; i < n; i++, s++) {
bool incol = false;
int i_col = 0;
+
+ if (mi > 1000) {
+ printf("\n");
+ ms.print();
+ mc.print();
+ md.print();
+ ma.print();
+ ml.print();
+ mi = 0;
+ }
+ mi++;
+
v[i] = Kst::NOPOINT;
- for (int ch = _rowIndex[s] - bufstart; ch < bufread; ++ch) {
+ for (int ch = _rowIndex[s] - bufstart; ch < bufread; ++ch) {
+ { M t(ms); isspace(_tmpBuf[ch]); }
if (isspace(_tmpBuf[ch])) {
if (_tmpBuf[ch] == '\n' || _tmpBuf[ch] == '\r') {
break;
} else {
incol = false;
}
- } else if (_config->_delimiters.contains(_tmpBuf[ch])) {
- break;
} else {
+ { M t(mc); _config->_delimiters.contains(_tmpBuf[ch]); }
+ if (_config->_delimiters.contains(_tmpBuf[ch])) {
+ break;
+ }
+ //} else {
if (!incol) {
incol = true;
++i_col;
if (i_col == col) {
+ { M t(md); (isdigit(_tmpBuf[ch]) || _tmpBuf[ch] == '-' ||
_tmpBuf[ch] == '.' || _tmpBuf[ch]); }
if (isdigit(_tmpBuf[ch]) || _tmpBuf[ch] == '-' || _tmpBuf[ch] ==
'.' || _tmpBuf[ch] == '+') {
- v[i] = atof(_tmpBuf + ch);
- } else if (ch + 2 < bufread && tolower(_tmpBuf[ch]) == 'i' &&
- tolower(_tmpBuf[ch + 1]) == 'n' && tolower(_tmpBuf[ch + 2])
== 'f') {
- v[i] = INF;
+#if 1
+ v[i] = atof(_tmpBuf + ch);
+ { M t(ma); atof(_tmpBuf + ch); }
+#else
+ v[i] = strtod(_tmpBuf + ch, 0);
+ { M t(ma); strtod(_tmpBuf + ch, 0); }
+#endif
+ } else {
+ { M t(ml); (ch + 2 < bufread && tolower(_tmpBuf[ch]) == 'i'
&& tolower(_tmpBuf[ch + 1]) == 'n' && tolower(_tmpBuf[ch + 2])); }
+ if (ch + 2 < bufread && tolower(_tmpBuf[ch]) == 'i' &&
+ tolower(_tmpBuf[ch + 1]) == 'n' && tolower(_tmpBuf[ch +
2]) == 'f') {
+ v[i] = INF;
+ }
}
break;
}
_______________________________________________
Kde-windows mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-windows