Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Speed Optimization of C++ console application

Speed Optimization of C++ console application

Scheduled Pinned Locked Moved Solved General and Desktop
25 Posts 10 Posters 4.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.
  • D Offline
    D Offline
    dooley
    wrote on 12 Dec 2019, 15:12 last edited by
    #1

    Hi,
    I am relatively new to programming and am a complete newbie to QT. I have been creating a C++ console application in visual studio 2017 that is basically the matrix calculation engine of a new app I want to develop. In visual studio, I optimized this program using the 02 speed optimization setting and the console app performs the calculations very quickly.

    Now that I have the calculation engine complete, I want to create a GUI for the program. That is when I turned to QT. To "get my feet wet" in QT I created a new simple C++ console app and brought in all of my header and source files. I inserted QMAKE_CXXFLAGS_RELEASE -= -O2 and QMAKE_CXXFLAGS_DEBUG -= -O2 into the .pro file and ran QMake. However, when I run the app itself it is approximately 10x slower than the same exact app compiled and run from VS.

    In VS2017 the total calculation time is 1.2 seconds
    In QT4.10.2 the same exact calculation time is 13.1 seconds

    Can anyone give me some pointers as to what I am missing?

    Thanks in advance....

    A K A 3 Replies Last reply 12 Dec 2019, 15:26
    0
    • D dooley
      12 Dec 2019, 15:12

      Hi,
      I am relatively new to programming and am a complete newbie to QT. I have been creating a C++ console application in visual studio 2017 that is basically the matrix calculation engine of a new app I want to develop. In visual studio, I optimized this program using the 02 speed optimization setting and the console app performs the calculations very quickly.

      Now that I have the calculation engine complete, I want to create a GUI for the program. That is when I turned to QT. To "get my feet wet" in QT I created a new simple C++ console app and brought in all of my header and source files. I inserted QMAKE_CXXFLAGS_RELEASE -= -O2 and QMAKE_CXXFLAGS_DEBUG -= -O2 into the .pro file and ran QMake. However, when I run the app itself it is approximately 10x slower than the same exact app compiled and run from VS.

      In VS2017 the total calculation time is 1.2 seconds
      In QT4.10.2 the same exact calculation time is 13.1 seconds

      Can anyone give me some pointers as to what I am missing?

      Thanks in advance....

      A Offline
      A Offline
      artwaw
      wrote on 12 Dec 2019, 15:26 last edited by
      #2

      @dooley Hi, you build it with mingw or MSVC?
      Also, could you please post your .pro file please?

      For more information please re-read.

      Kind Regards,
      Artur

      D 1 Reply Last reply 12 Dec 2019, 20:40
      2
      • D dooley
        12 Dec 2019, 15:12

        Hi,
        I am relatively new to programming and am a complete newbie to QT. I have been creating a C++ console application in visual studio 2017 that is basically the matrix calculation engine of a new app I want to develop. In visual studio, I optimized this program using the 02 speed optimization setting and the console app performs the calculations very quickly.

        Now that I have the calculation engine complete, I want to create a GUI for the program. That is when I turned to QT. To "get my feet wet" in QT I created a new simple C++ console app and brought in all of my header and source files. I inserted QMAKE_CXXFLAGS_RELEASE -= -O2 and QMAKE_CXXFLAGS_DEBUG -= -O2 into the .pro file and ran QMake. However, when I run the app itself it is approximately 10x slower than the same exact app compiled and run from VS.

        In VS2017 the total calculation time is 1.2 seconds
        In QT4.10.2 the same exact calculation time is 13.1 seconds

        Can anyone give me some pointers as to what I am missing?

        Thanks in advance....

        K Offline
        K Offline
        KroMignon
        wrote on 12 Dec 2019, 15:31 last edited by KroMignon 12 Dec 2019, 15:43
        #3

        @dooley said in Speed Optimization of C++ console application:

        In QT4.10.2 the same exact calculation time is 13.1 seconds

        QtCreator is just an IDE, it depends on which Qt Kit (MSVC2017, MinGW, etc..) you have used for your project and in what configuration (release, debug or profile) you have build the project.

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        1 Reply Last reply
        3
        • D dooley
          12 Dec 2019, 15:12

          Hi,
          I am relatively new to programming and am a complete newbie to QT. I have been creating a C++ console application in visual studio 2017 that is basically the matrix calculation engine of a new app I want to develop. In visual studio, I optimized this program using the 02 speed optimization setting and the console app performs the calculations very quickly.

          Now that I have the calculation engine complete, I want to create a GUI for the program. That is when I turned to QT. To "get my feet wet" in QT I created a new simple C++ console app and brought in all of my header and source files. I inserted QMAKE_CXXFLAGS_RELEASE -= -O2 and QMAKE_CXXFLAGS_DEBUG -= -O2 into the .pro file and ran QMake. However, when I run the app itself it is approximately 10x slower than the same exact app compiled and run from VS.

          In VS2017 the total calculation time is 1.2 seconds
          In QT4.10.2 the same exact calculation time is 13.1 seconds

          Can anyone give me some pointers as to what I am missing?

          Thanks in advance....

          A Offline
          A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on 12 Dec 2019, 16:18 last edited by
          #4

          @dooley said in Speed Optimization of C++ console application:

          QMAKE_CXXFLAGS_RELEASE -= -O2

          Shouldn't that be QMAKE_CXXFLAGS_RELEASE += -O2 if you want to optimize for speed?

          Regards

          Qt has to stay free or it will die.

          J 1 Reply Last reply 12 Dec 2019, 20:33
          6
          • A aha_1980
            12 Dec 2019, 16:18

            @dooley said in Speed Optimization of C++ console application:

            QMAKE_CXXFLAGS_RELEASE -= -O2

            Shouldn't that be QMAKE_CXXFLAGS_RELEASE += -O2 if you want to optimize for speed?

            Regards

            J Offline
            J Offline
            JonB
            wrote on 12 Dec 2019, 20:33 last edited by JonB 12 Dec 2019, 20:40
            #5

            @aha_1980
            Good catch! Now if people put

            `code`
            

            tags into their questions like you have we would be able to spot these things :)

            1 Reply Last reply
            2
            • A artwaw
              12 Dec 2019, 15:26

              @dooley Hi, you build it with mingw or MSVC?
              Also, could you please post your .pro file please?

              D Offline
              D Offline
              dooley
              wrote on 12 Dec 2019, 20:40 last edited by
              #6

              @artwaw I am building with MSVC 2017 64 bit .

              I must be doing something wrong because I am getting the same calculation speed if I include
              the CXXFlags in hte pro file or not. In visual studio there was dramatic 20x speed increase in the app by just adding 02 optimization.

              I have pasted my pro file below

              TEMPLATE = app
              CONFIG += console c++11
              CONFIG -= app_bundle
              CONFIG -= qt
              
              
              QMAKE_CXXFLAGS_RELEASE -= -O2
              
              
              SOURCES += \
                      CVSReader.cpp \
                      ComponentManagement.cpp \
                      MatrixUtilities.cpp \
                      Nodes.cpp \
                      Pipes.cpp \
                      Tanks.cpp \
                      VectorUtilities.cpp \
                      main.cpp
              
              HEADERS += \
                  CVSReader.h \
                  ComponentManagement.h \
                  Globals.h \
                  MatrixUtilities.h \
                  Nodes.h \
                  Pipes.h \
                  Tanks.h \
                  VectorUtilities.h \
                  resource.h
              
              
              INCLUDEPATH += $$PWD/../C++Libraries/Eigin3.3.7
              DEPENDPATH += $$PWD/../C++Libraries/Eigin3.3.7
              
              J 1 Reply Last reply 12 Dec 2019, 20:42
              0
              • D dooley
                12 Dec 2019, 20:40

                @artwaw I am building with MSVC 2017 64 bit .

                I must be doing something wrong because I am getting the same calculation speed if I include
                the CXXFlags in hte pro file or not. In visual studio there was dramatic 20x speed increase in the app by just adding 02 optimization.

                I have pasted my pro file below

                TEMPLATE = app
                CONFIG += console c++11
                CONFIG -= app_bundle
                CONFIG -= qt
                
                
                QMAKE_CXXFLAGS_RELEASE -= -O2
                
                
                SOURCES += \
                        CVSReader.cpp \
                        ComponentManagement.cpp \
                        MatrixUtilities.cpp \
                        Nodes.cpp \
                        Pipes.cpp \
                        Tanks.cpp \
                        VectorUtilities.cpp \
                        main.cpp
                
                HEADERS += \
                    CVSReader.h \
                    ComponentManagement.h \
                    Globals.h \
                    MatrixUtilities.h \
                    Nodes.h \
                    Pipes.h \
                    Tanks.h \
                    VectorUtilities.h \
                    resource.h
                
                
                INCLUDEPATH += $$PWD/../C++Libraries/Eigin3.3.7
                DEPENDPATH += $$PWD/../C++Libraries/Eigin3.3.7
                
                J Offline
                J Offline
                JonB
                wrote on 12 Dec 2019, 20:42 last edited by
                #7

                @dooley said in Speed Optimization of C++ console application:

                QMAKE_CXXFLAGS_RELEASE -= -O2

                Have you read @aha_1980 's answer above?

                D 1 Reply Last reply 12 Dec 2019, 20:53
                0
                • J JonB
                  12 Dec 2019, 20:42

                  @dooley said in Speed Optimization of C++ console application:

                  QMAKE_CXXFLAGS_RELEASE -= -O2

                  Have you read @aha_1980 's answer above?

                  D Offline
                  D Offline
                  dooley
                  wrote on 12 Dec 2019, 20:53 last edited by
                  #8

                  @JonB Yes I saw it. I did try changing it to QMAKE_CXXFLAGS_RELEASE += -02 as suggested and saw no improvement. I will change it back if that is the correct way to insert it... like I said I am new to QT and saw the -= format in another post and was tying it.

                  Thanks for the response... do you have any other thoughts as to why I don't see an increase in speed?

                  Sorry it took so long to respond to you but since I am a new user I have to wait 600 seconds between posts.

                  A 1 Reply Last reply 12 Dec 2019, 20:57
                  1
                  • D dooley
                    12 Dec 2019, 20:53

                    @JonB Yes I saw it. I did try changing it to QMAKE_CXXFLAGS_RELEASE += -02 as suggested and saw no improvement. I will change it back if that is the correct way to insert it... like I said I am new to QT and saw the -= format in another post and was tying it.

                    Thanks for the response... do you have any other thoughts as to why I don't see an increase in speed?

                    Sorry it took so long to respond to you but since I am a new user I have to wait 600 seconds between posts.

                    A Offline
                    A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on 12 Dec 2019, 20:57 last edited by
                    #9

                    @dooley

                    So are you actually building a release version?

                    Please show your compiler output so we see the flags passed to the compiler.

                    Sorry it took so long to respond to you but since I am a new user I have to wait 600 seconds between posts.

                    No longer, I gave you an upvote :)

                    Regards

                    Qt has to stay free or it will die.

                    D 3 Replies Last reply 12 Dec 2019, 21:09
                    1
                    • A aha_1980
                      12 Dec 2019, 20:57

                      @dooley

                      So are you actually building a release version?

                      Please show your compiler output so we see the flags passed to the compiler.

                      Sorry it took so long to respond to you but since I am a new user I have to wait 600 seconds between posts.

                      No longer, I gave you an upvote :)

                      Regards

                      D Offline
                      D Offline
                      dooley
                      wrote on 12 Dec 2019, 21:09 last edited by
                      #10

                      @aha_1980 Here is the compiler output...

                      15:08:01: Running steps for project SF_1...
                      15:08:01: Configuration unchanged, skipping qmake step.
                      15:08:01: Starting: "C:\Qt1\Tools\QtCreator\bin\jom.exe" 
                      	C:\Qt1\Tools\QtCreator\bin\jom.exe -f Makefile.Release
                      15:08:01: The process "C:\Qt1\Tools\QtCreator\bin\jom.exe" exited normally.
                      15:08:01: Elapsed time: 00:00.
                      
                      1 Reply Last reply
                      0
                      • A aha_1980
                        12 Dec 2019, 20:57

                        @dooley

                        So are you actually building a release version?

                        Please show your compiler output so we see the flags passed to the compiler.

                        Sorry it took so long to respond to you but since I am a new user I have to wait 600 seconds between posts.

                        No longer, I gave you an upvote :)

                        Regards

                        D Offline
                        D Offline
                        dooley
                        wrote on 12 Dec 2019, 21:20 last edited by
                        #11

                        @aha_1980 This is probably more usefull :)

                        15:18:51: Running steps for project SF_1...
                        15:18:51: Starting: "C:\Qt1\Tools\QtCreator\bin\jom.exe" clean
                        	C:\Qt1\Tools\QtCreator\bin\jom.exe -f Makefile.Release clean
                        	del release\CVSReader.obj release\ComponentManagement.obj release\MatrixUtilities.obj release\Nodes.obj release\Pipes.obj release\Tanks.obj release\VectorUtilities.obj release\main.obj
                        	C:\Qt1\Tools\QtCreator\bin\jom.exe -f Makefile.Debug clean
                        	del debug\CVSReader.obj debug\ComponentManagement.obj debug\MatrixUtilities.obj debug\Nodes.obj debug\Pipes.obj debug\Tanks.obj debug\VectorUtilities.obj debug\main.obj
                        	del debug\SF_1.vc.pdb debug\SF_1.ilk debug\SF_1.idb
                        Could Not Find C:\Users\heath\Documents\build-SF_1-Desktop_x86_windows_msvc2017_pe_64bit-Release\debug\CVSReader.obj
                        Could Not Find C:\Users\heath\Documents\build-SF_1-Desktop_x86_windows_msvc2017_pe_64bit-Release\debug\SF_1.vc.pdb
                        15:18:52: The process "C:\Qt1\Tools\QtCreator\bin\jom.exe" exited normally.
                        15:18:52: Starting: "C:\Qt1\5.13.1\msvc2017_64\bin\qmake.exe" C:\Users\heath\Documents\SF_1\SF_1.pro -spec win32-msvc "CONFIG+=qtquickcompiler"
                        15:18:52: The process "C:\Qt1\5.13.1\msvc2017_64\bin\qmake.exe" exited normally.
                        15:18:52: Starting: "C:\Qt1\Tools\QtCreator\bin\jom.exe" -f C:/Users/heath/Documents/build-SF_1-Desktop_x86_windows_msvc2017_pe_64bit-Release/Makefile qmake_all
                        
                        jom 1.1.3 - empower your cores
                        
                        15:18:52: The process "C:\Qt1\Tools\QtCreator\bin\jom.exe" exited normally.
                        15:18:52: Starting: "C:\Qt1\Tools\QtCreator\bin\jom.exe" 
                        	C:\Qt1\Tools\QtCreator\bin\jom.exe -f Makefile.Release
                        	cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -O2 -MD -O2 -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DNDEBUG -I..\SF_1 -I. -I..\C++Libraries\Eigin3.3.7 -I..\..\..\..\Qt1\5.13.1\msvc2017_64\mkspecs\win32-msvc -Forelease\ @C:\Users\heath\AppData\Local\Temp\CVSReader.obj.4364.15.jom
                        CVSReader.cpp
                        	cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -O2 -MD -O2 -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DNDEBUG -I..\SF_1 -I. -I..\C++Libraries\Eigin3.3.7 -I..\..\..\..\Qt1\5.13.1\msvc2017_64\mkspecs\win32-msvc -Forelease\ @C:\Users\heath\AppData\Local\Temp\VectorUtilities.obj.4364.78.jom
                        VectorUtilities.cpp
                        ..\SF_1\VectorUtilities.cpp(43): warning C4244: '=': conversion from '__int64' to 'int', possible loss of data
                        ..\SF_1\VectorUtilities.cpp(55): warning C4244: '=': conversion from '__int64' to 'int', possible loss of data
                        ..\SF_1\VectorUtilities.cpp(60): warning C4244: '=': conversion from '__int64' to 'int', possible loss of data
                        ..\SF_1\VectorUtilities.cpp(70): warning C4189: 'tmp': local variable is initialized but not referenced
                        ..\SF_1\VectorUtilities.cpp(96): warning C4189: 'tmp': local variable is initialized but not referenced
                        ..\SF_1\CVSReader.cpp(16): warning C4189: 'numLines': local variable is initialized but not referenced
                        ..\SF_1\CVSReader.cpp(14): warning C4189: 'newLine': local variable is initialized but not referenced
                        	cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -O2 -MD -O2 -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DNDEBUG -I..\SF_1 -I. -I..\C++Libraries\Eigin3.3.7 -I..\..\..\..\Qt1\5.13.1\msvc2017_64\mkspecs\win32-msvc -Forelease\ @C:\Users\heath\AppData\Local\Temp\Nodes.obj.4364.47.jom
                        Nodes.cpp
                        	cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -O2 -MD -O2 -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DNDEBUG -I..\SF_1 -I. -I..\C++Libraries\Eigin3.3.7 -I..\..\..\..\Qt1\5.13.1\msvc2017_64\mkspecs\win32-msvc -Forelease\ @C:\Users\heath\AppData\Local\Temp\ComponentManagement.obj.4364.15.jom
                        ComponentManagement.cpp
                        	cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -O2 -MD -O2 -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DNDEBUG -I..\SF_1 -I. -I..\C++Libraries\Eigin3.3.7 -I..\..\..\..\Qt1\5.13.1\msvc2017_64\mkspecs\win32-msvc -Forelease\ @C:\Users\heath\AppData\Local\Temp\MatrixUtilities.obj.4364.31.jom
                        MatrixUtilities.cpp
                        ..\SF_1\MatrixUtilities.cpp(367): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
                        ..\SF_1\MatrixUtilities.cpp(437): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
                        ..\SF_1\MatrixUtilities.cpp(385): warning C4189: 'tFI_T': local variable is initialized but not referenced
                        ..\SF_1\MatrixUtilities.cpp(456): warning C4189: 'Ed': local variable is initialized but not referenced
                        ..\SF_1\MatrixUtilities.cpp(829): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
                        ..\SF_1\MatrixUtilities.cpp(829): warning C4189: 'loopcnt': local variable is initialized but not referenced
                        ..\SF_1\MatrixUtilities.cpp(866): warning C4189: 'cheker': local variable is initialized but not referenced
                        ..\SF_1\MatrixUtilities.cpp(860): warning C4189: 'end': local variable is initialized but not referenced
                        	cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -O2 -MD -O2 -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DNDEBUG -I..\SF_1 -I. -I..\C++Libraries\Eigin3.3.7 -I..\..\..\..\Qt1\5.13.1\msvc2017_64\mkspecs\win32-msvc -Forelease\ @C:\Users\heath\AppData\Local\Temp\Pipes.obj.4364.47.jom
                        Pipes.cpp
                        	cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -O2 -MD -O2 -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DNDEBUG -I..\SF_1 -I. -I..\C++Libraries\Eigin3.3.7 -I..\..\..\..\Qt1\5.13.1\msvc2017_64\mkspecs\win32-msvc -Forelease\ @C:\Users\heath\AppData\Local\Temp\Tanks.obj.4364.62.jom
                        Tanks.cpp
                        	cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -O2 -MD -O2 -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DNDEBUG -I..\SF_1 -I. -I..\C++Libraries\Eigin3.3.7 -I..\..\..\..\Qt1\5.13.1\msvc2017_64\mkspecs\win32-msvc -Forelease\ @C:\Users\heath\AppData\Local\Temp\main.obj.4364.94.jom
                        main.cpp
                        ..\SF_1\main.cpp(33): warning C4101: 'my_documents': unreferenced local variable
                        	link /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:release\SF_1.exe @C:\Users\heath\AppData\Local\Temp\SF_1.exe.4364.7000.jom
                        15:18:59: The process "C:\Qt1\Tools\QtCreator\bin\jom.exe" exited normally.
                        15:18:59: Elapsed time: 00:08.
                        
                        1 Reply Last reply
                        0
                        • A aha_1980
                          12 Dec 2019, 20:57

                          @dooley

                          So are you actually building a release version?

                          Please show your compiler output so we see the flags passed to the compiler.

                          Sorry it took so long to respond to you but since I am a new user I have to wait 600 seconds between posts.

                          No longer, I gave you an upvote :)

                          Regards

                          D Offline
                          D Offline
                          dooley
                          wrote on 12 Dec 2019, 22:28 last edited by
                          #12

                          @aha_1980 After having taken your and @aha_1980 direction on the annotation and rebuilding it appears to be working.

                          Thanks to everyone for the help. I am a civil engineer putting together some simple apps for calculations I use regularly more for fun and the interest in programming than anything else, so I don't know a whole lot and can use as much help as I can get.

                          J 1 Reply Last reply 16 Dec 2019, 10:11
                          3
                          • fcarneyF Offline
                            fcarneyF Offline
                            fcarney
                            wrote on 12 Dec 2019, 22:57 last edited by
                            #13

                            @dooley said in Speed Optimization of C++ console application:

                            civil engineer

                            Ah, a "target" maker. Welcome aboard!

                            C++ is a perfectly valid school of magic.

                            1 Reply Last reply
                            0
                            • beeckscheB Offline
                              beeckscheB Offline
                              beecksche
                              wrote on 13 Dec 2019, 10:00 last edited by beecksche
                              #14

                              When building in Release mode, the optimization flag -O2 should be set by default.

                              If speed is an issue and using lots of loops you can also enable the logs for Auto-Vectorization:

                              QMAKE_CXXFLAGS_RELEASE += -Qvec-report:2
                              

                              Then all vectorized and non-vectorized loops will be logged and you can see where loops can be imporved. For some loops it's neccessary to set

                              QMAKE_CXXFLAGS_RELEASE += -fp:fast
                              

                              to be vectorized. But be careful with that!

                              Another way to speed up the program is to set the -Qpar flag for Auto-Parallelization:

                              QMAKE_CXXFLAGS_RELEASE += -Qpar
                              

                              Then, if possible, loops will be parallelized. There is also an log flag for that -QPar-report:2.

                              Please note, only valid for MSVC compiler and CPU architure with SSE2, AVX, and AVX2.

                              kshegunovK 1 Reply Last reply 15 Dec 2019, 09:28
                              4
                              • beeckscheB beecksche
                                13 Dec 2019, 10:00

                                When building in Release mode, the optimization flag -O2 should be set by default.

                                If speed is an issue and using lots of loops you can also enable the logs for Auto-Vectorization:

                                QMAKE_CXXFLAGS_RELEASE += -Qvec-report:2
                                

                                Then all vectorized and non-vectorized loops will be logged and you can see where loops can be imporved. For some loops it's neccessary to set

                                QMAKE_CXXFLAGS_RELEASE += -fp:fast
                                

                                to be vectorized. But be careful with that!

                                Another way to speed up the program is to set the -Qpar flag for Auto-Parallelization:

                                QMAKE_CXXFLAGS_RELEASE += -Qpar
                                

                                Then, if possible, loops will be parallelized. There is also an log flag for that -QPar-report:2.

                                Please note, only valid for MSVC compiler and CPU architure with SSE2, AVX, and AVX2.

                                kshegunovK Offline
                                kshegunovK Offline
                                kshegunov
                                Moderators
                                wrote on 15 Dec 2019, 09:28 last edited by
                                #15

                                @beecksche said in Speed Optimization of C++ console application:

                                QMAKE_CXXFLAGS_RELEASE += -fp:fast
                                

                                Don't use this unless you really, really, really (and I can't emphasize that enough) know what you're doing (which is almost never). This can break promises made by the IEEE FP standard in regards to behavior and optimize out expressions that are not to be optimized. It can break proper rounding and error propagation, and floating point exceptions' diagnostics.

                                Read and abide by the Qt Code of Conduct

                                1 Reply Last reply
                                5
                                • Kent-DorfmanK Offline
                                  Kent-DorfmanK Offline
                                  Kent-Dorfman
                                  wrote on 16 Dec 2019, 03:59 last edited by
                                  #16

                                  A code slowdown of a factor of 10 wouldn't be normal just with an optimization flag of -O0 vs -O2. Something else is going on here. The OP only states C++ in VS2017...No mention of CLR or native code generation in VS. Actually I'd expect the converse of the reported behaviour, where the native C++ QT runs faster if the VS C++ code is done as CLR and not native. If I had to WAG, I'd guess that the VS code is taking advantage of a .net library optimization that isn't present in native C++ QT. Without seeing the algorithms and the library links it's hard to know what exactly is going on. Heap managed memory could also play a large part in the time differences being reported.

                                  kshegunovK 1 Reply Last reply 16 Dec 2019, 09:52
                                  0
                                  • Christian EhrlicherC Online
                                    Christian EhrlicherC Online
                                    Christian Ehrlicher
                                    Lifetime Qt Champion
                                    wrote on 16 Dec 2019, 05:31 last edited by
                                    #17

                                    @Kent-Dorfman said in Speed Optimization of C++ console application:

                                    A code slowdown of a factor of 10 wouldn't be normal just with an optimization flag of -O0 vs -O2.

                                    Why not? Did you see the code? Maybe there are lots of asserts in there or other stuff... without code it's just wild guessing.

                                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                    Visit the Qt Academy at https://academy.qt.io/catalog

                                    1 Reply Last reply
                                    3
                                    • Kent-DorfmanK Kent-Dorfman
                                      16 Dec 2019, 03:59

                                      A code slowdown of a factor of 10 wouldn't be normal just with an optimization flag of -O0 vs -O2. Something else is going on here. The OP only states C++ in VS2017...No mention of CLR or native code generation in VS. Actually I'd expect the converse of the reported behaviour, where the native C++ QT runs faster if the VS C++ code is done as CLR and not native. If I had to WAG, I'd guess that the VS code is taking advantage of a .net library optimization that isn't present in native C++ QT. Without seeing the algorithms and the library links it's hard to know what exactly is going on. Heap managed memory could also play a large part in the time differences being reported.

                                      kshegunovK Offline
                                      kshegunovK Offline
                                      kshegunov
                                      Moderators
                                      wrote on 16 Dec 2019, 09:52 last edited by
                                      #18

                                      @Kent-Dorfman said in Speed Optimization of C++ console application:

                                      A code slowdown of a factor of 10 wouldn't be normal just with an optimization flag of -O0 vs -O2.

                                      Actually it can be pretty normal. I've at least two rather small codebases that exhibit such speedups between debug and release (i.e. -g -O0 vs -O2). There's nothing odd about it because debug mode represents what you wrote faithfully, which isn't at all true for release builds.

                                      Something else is going on here.

                                      Not necessarily. Depends on the type of code. If you have code with a lot of templates for example the debug build is going to put a call instruction on every function call and do the regular push, pop on the stack. When the optimizer runs almost, to all, of this gets stripped down and the code is inlined, to an extreme degree. So yes, 10 time speedup between debug and release is nothing to be suspicious about.

                                      Read and abide by the Qt Code of Conduct

                                      Kent-DorfmanK 1 Reply Last reply 16 Dec 2019, 22:27
                                      3
                                      • D dooley
                                        12 Dec 2019, 22:28

                                        @aha_1980 After having taken your and @aha_1980 direction on the annotation and rebuilding it appears to be working.

                                        Thanks to everyone for the help. I am a civil engineer putting together some simple apps for calculations I use regularly more for fun and the interest in programming than anything else, so I don't know a whole lot and can use as much help as I can get.

                                        J Offline
                                        J Offline
                                        JonB
                                        wrote on 16 Dec 2019, 10:11 last edited by
                                        #19

                                        @dooley
                                        What the others are saying about optimization vs debug is probably correct, you can be surprised by how much difference it can make depending.

                                        However, if you are sure about your compiler flags etc. but are still stumped by speed behaviour, it may be time to compile/link for profiling your application. Both gcc & msvc have profiling (unless the free msvc does not, I don't know). This does take a bit of reading first time to set up and interpret output, but well worth it if you wish to investigate speed/performance over time in future.

                                        1 Reply Last reply
                                        2
                                        • kshegunovK kshegunov
                                          16 Dec 2019, 09:52

                                          @Kent-Dorfman said in Speed Optimization of C++ console application:

                                          A code slowdown of a factor of 10 wouldn't be normal just with an optimization flag of -O0 vs -O2.

                                          Actually it can be pretty normal. I've at least two rather small codebases that exhibit such speedups between debug and release (i.e. -g -O0 vs -O2). There's nothing odd about it because debug mode represents what you wrote faithfully, which isn't at all true for release builds.

                                          Something else is going on here.

                                          Not necessarily. Depends on the type of code. If you have code with a lot of templates for example the debug build is going to put a call instruction on every function call and do the regular push, pop on the stack. When the optimizer runs almost, to all, of this gets stripped down and the code is inlined, to an extreme degree. So yes, 10 time speedup between debug and release is nothing to be suspicious about.

                                          Kent-DorfmanK Offline
                                          Kent-DorfmanK Offline
                                          Kent-Dorfman
                                          wrote on 16 Dec 2019, 22:27 last edited by
                                          #20

                                          @kshegunov I wrote absolutely nothing about "-g". I still maintain that simple -O0 vs -O2 is NOT going to divide performance by a factor of 10. I cannot begin to imagine how badly a person would have to design their algorithm to validate that level of performance hit. something other than compiler optimization is causing his hit...

                                          kshegunovK A 2 Replies Last reply 17 Dec 2019, 21:18
                                          0

                                          5/25

                                          12 Dec 2019, 20:33

                                          topic:navigator.unread, 20
                                          • Login

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