Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Performance issues with simple test on Qt5 vs Qt4 on ARM device without GPU

Performance issues with simple test on Qt5 vs Qt4 on ARM device without GPU

Scheduled Pinned Locked Moved Mobile and Embedded
armlinuxqt5 vs qt4performanceembedded linux
4 Posts 2 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hirandom
    wrote on 25 Mar 2015, 07:42 last edited by hirandom
    #1

    Hello!

    I've been running some simple tests on Qt5.4.1 and Qt4.8.6 on an ARM processor without a GPU (so on Qt5, the program uses linuxfb, and on Qt4, it uses the QWS). I expected Qt5 to be faster because it won't have the overhead of the QWS, but my tests show otherwise.

    Here is what I used to test it:

    //lines.h
    #pragma once
    #include <QWidget>
    class Lines : public QWidget
    {
    	Q_OBJECT
    	public:
    		Lines(QWidget *parent = 0);
    
    	public slots:
    		void animate();	
    
    	protected:
    		void paintEvent(QPaintEvent *event);
    		void drawLines(QPainter *qp);
    		int frameCounter;
    };
    
    //lines.cpp
    #include "lines.h"
    #include <QPainter>
    #include <stdio.h>
    #include <QTimer>
    #include <QTime>
    
    #define NUMSHAPES 1000
    QTime t;
    
    Lines::Lines(QWidget *parent) : QWidget(parent) 
    {
    	frameCounter = 0;
    
    	QTimer *timer = new QTimer(this);
    	connect(timer, SIGNAL(timeout()), this, SLOT(animate()));
    
    	#ifndef QT4USED
    	timer->setTimerType(Qt::PreciseTimer);
    	#endif
    
    	timer->start(10);	
    	t.start();
    }
    
    void Lines::paintEvent(QPaintEvent *e) 
    { 
    	Q_UNUSED(e);
    	QPainter qp(this);
    	drawLines(&qp);
    
    	double a = t.restart();	  	
    	fprintf(stderr,"time: %lf fps: %lf\n", a, 1000.0/a);
    }	
    
    void Lines::animate() 
    {
    	frameCounter++;
    	//repaint();
    	update();	
    }
    
    void Lines::drawLines(QPainter *qp) 
    { 
    	for ( int c = 0; c < NUMSHAPES; c++ )
    	{		
    		QPen pen(Qt::red, 1, Qt::SolidLine);  
    		qp->setPen(pen);
    		int xbegin, xend, ybegin, yend ;
    		xbegin = xend = frameCounter*10;
    		ybegin = 0;
    		yend= 250;
    		
    		qp->drawLine( xbegin, ybegin, xend, yend );
    	}
    }
    
    
    //main.cpp
    #include "lines.h"
    #include <QApplication>
    #include <stdio.h>
    int main(int argc, char *argv[]) 
    {
    	QApplication app(argc, argv);
    	Lines window;
    
    	window.resize(640, 480);
    	window.setWindowTitle("Lines");
    	window.show();
    
    	return app.exec();
    }
    

    In summary, the code starts a timer with an interval of 10 msecs, and calls update() on the Lines widget. The widget itself paints a 1000 drawLines() every frame, and then outputs the time taken between each frame to stderr.

    This program causes 100% cpu usage on both Qt5 and Qt4, but Qt5 takes an average of 55 msecs per frame, while Qt4 takes 50. While this isn't too different, does anyone have a clue why Qt5 is actually slower? Shouldn't it be at least as fast because the QWS is out of the picture?

    But the bigger problem is the CPU usage when the widget paints a 100 lines every frame instead of 1000. On Qt5, it paints a frame every 13 milliseconds, and the CPU usage is still 100%, but on Qt4, it paints a frame every 10 milliseconds and the CPU usage is about 85%. Any ideas why Qt5 seems to be underperforming?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 25 Mar 2015, 08:10 last edited by
      #2

      Interesting. Could you try running both "versions" through callgrind or some other profiling tool? Maybe that will help somewhat.

      The only code difference you add here (between Qt 4 and 5) is timer precision - but that should not make much difference (please check, though).

      The only thing I can think of right now is that QPainter's handling of thin lines and antialiasing has been slightly changed when going from Qt 4 to Qt 5. So perhaps Qt 5 is using more time to properly draw the line. Or the reason could be completely different: maybe linuxfb painting is slower on your device?

      (Z(:^

      H 1 Reply Last reply 26 Mar 2015, 01:33
      0
      • S sierdzio
        25 Mar 2015, 08:10

        Interesting. Could you try running both "versions" through callgrind or some other profiling tool? Maybe that will help somewhat.

        The only code difference you add here (between Qt 4 and 5) is timer precision - but that should not make much difference (please check, though).

        The only thing I can think of right now is that QPainter's handling of thin lines and antialiasing has been slightly changed when going from Qt 4 to Qt 5. So perhaps Qt 5 is using more time to properly draw the line. Or the reason could be completely different: maybe linuxfb painting is slower on your device?

        H Offline
        H Offline
        hirandom
        wrote on 26 Mar 2015, 01:33 last edited by
        #3

        @sierdzio Thanks a lot for the reply!
        I'll try running it through a profiler, and looking through the QPainter source. Out of curiosity, I also tried painting absolutely nothing in the paint event, so that all the timer will do is call update() every 10 milliseconds. In Qt4, that gave me a 100% idle cpu, but in Qt5, it was about 15% idle. So I changed the update() call to a repaint() call, and saw that the Qt4 idle time dropped to 33%, but the Qt5 one had no change(still 15% idle)...Were there any major changes to how Qt updates/repaints between 4 and 5?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 26 Mar 2015, 06:45 last edited by
          #4

          Hm. You would have to ask Qt developers (on IRC, or development mailing list) to get a definite answer. In Qt4->5 transition, the whole painting architecture was changed, so it is understandable there are differences in performance. What is not so good is that (from your data, and sporadic reports I see in other places) the performance of Qt5 is worse instead of better.

          (Z(:^

          1 Reply Last reply
          0

          4/4

          26 Mar 2015, 06:45

          • Login

          • Login or register to search.
          4 out of 4
          • First post
            4/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved