
Originally Posted by
wysota
As I said, the slowdown might be caused by your particular system configuration. How are you measuring the speed by the way?
It's not specific to "my configuration", I tested both the stock qt 5.0 from Ubuntu 13.04's repos and qt 5.1 which I compiled from source - same outcome.
As to how I measure, also simple: clock_gettime(CLOCK_MONOTONIC_RAW, ...) before and after QApplication (argc, argv) and compute the difference.
In case you care here's what the mtl::misc::Timer class looks like:
Timer.hpp:
#ifndef MTL_MISC_TIMER_HPP_
#define MTL_MISC_TIMER_HPP_
#include "../err.hpp"
#include "../misc.hpp"
#include <stdint.h>
#include <time.h>
namespace mtl {
namespace misc {
class Timer {
public:
Timer(const bool do_start = false) {
if (do_start) Start();
}
virtual ~Timer() {}
uint32_t
GetMicro() {
return mtl::misc::GetDiffMc(last_time, now_time);
}
uint32_t
GetMs() {
return mtl::misc::GetDiffMs(last_time, now_time);
}
void
Print(const char *comment, const bool do_stop = true);
void
Start() {
clock_gettime(CLOCK_MONOTONIC_RAW, &last_time);
}
void
Stop() {
clock_gettime(CLOCK_MONOTONIC_RAW, &now_time);
}
private:
DISALLOW_COPY_AND_ASSIGN(Timer);
struct timespec last_time;
struct timespec now_time;
};
} // namespace misc
} // namespace mtl
#endif
#ifndef MTL_MISC_TIMER_HPP_
#define MTL_MISC_TIMER_HPP_
#include "../err.hpp"
#include "../misc.hpp"
#include <stdint.h>
#include <time.h>
namespace mtl {
namespace misc {
class Timer {
public:
Timer(const bool do_start = false) {
if (do_start) Start();
}
virtual ~Timer() {}
uint32_t
GetMicro() {
return mtl::misc::GetDiffMc(last_time, now_time);
}
uint32_t
GetMs() {
return mtl::misc::GetDiffMs(last_time, now_time);
}
void
Print(const char *comment, const bool do_stop = true);
void
Start() {
clock_gettime(CLOCK_MONOTONIC_RAW, &last_time);
}
void
Stop() {
clock_gettime(CLOCK_MONOTONIC_RAW, &now_time);
}
private:
DISALLOW_COPY_AND_ASSIGN(Timer);
struct timespec last_time;
struct timespec now_time;
};
} // namespace misc
} // namespace mtl
#endif
To copy to clipboard, switch view to plain text mode
Timer.cpp:
#include "Timer.hpp"
namespace mtl {
namespace misc {
void
Timer::Print(const char *comment, const bool do_stop)
{
if(do_stop) {
Stop();
}
uint32_t diff = GetMs();
const char *symbol = "ms";
if (diff == 0) {
diff = GetMicro();
symbol = "μs";
}
printf("%s: %d %s\n", comment, diff, symbol);
}
} // namespace misc
} // namespace mtl
#include "Timer.hpp"
namespace mtl {
namespace misc {
void
Timer::Print(const char *comment, const bool do_stop)
{
if(do_stop) {
Stop();
}
uint32_t diff = GetMs();
const char *symbol = "ms";
if (diff == 0) {
diff = GetMicro();
symbol = "μs";
}
printf("%s: %d %s\n", comment, diff, symbol);
}
} // namespace misc
} // namespace mtl
To copy to clipboard, switch view to plain text mode
Usage:
mtl::misc::Timer timer(true);
timer.Print("qapp creation");
mtl::misc::Timer timer(true);
QApplication app(argc, argv);
timer.Print("qapp creation");
To copy to clipboard, switch view to plain text mode
Bookmarks