Results 1 to 10 of 10

Thread: Why qt execution is so slow,this is a test

  1. #1
    Join Date
    Feb 2012
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Why qt execution is so slow,this is a test

    Testing machine:
    win7
    8G
    I7 2600

    qt4.7.4 php5.3.8 python 2.6

    run with qt
    Qt Code:
    1. t.start();
    2. QString aa="";
    3. for(int i=0;i<=1000000;i++){
    4. aa += "1";
    5. }
    6. printf("used: %d ms", t.elapsed());
    To copy to clipboard, switch view to plain text mode 

    debug :240ms
    release:138ms


    run with php
    Qt Code:
    1. $time = new runtime;
    2. $time->start();
    3. $str = "";
    4. for ($i = 0; $i <= 1000000; $i++) {
    5. $str.="1";
    6. }
    7. $time->stop();
    8. echo "used:" . $time->spent() . "ms";
    To copy to clipboard, switch view to plain text mode 
    used time :92.9ms


    run with python:
    Qt Code:
    1. import os,sys
    2. from time import clock as now
    3. start = now()
    4. str = ""
    5. for i in range(0,1000000):
    6. str += "i"
    7. finish = now()
    8. print (finish-start)
    To copy to clipboard, switch view to plain text mode 
    used time:210ms

    run with qt c++:
    Qt Code:
    1. t.start();
    2. char *pStr = new char[1000001];
    3. for(int i=0;i<=1000000;i++){
    4. pStr[i] = '1';
    5. }
    6. delete pStr;
    7. printf("used: %d ms",t.elapsed());
    To copy to clipboard, switch view to plain text mode 

    debug,3ms
    release,1ms

    not just this one test,every test just faster to python,there is no php half of the fast
    is this my qt configuration's problem?
    some one answer me,please

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why qt execution is so slow,this is a test

    Comparing apples to monkeys using a grandpa's clock doesn't yield any practical results.

    By the way, yes -- appending single characters to QString is quite slow. However it's not a problem for me since I'm not often adding thousands of single characters to a string in a loop in my programs. Such apps are quite boring.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2012
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why qt execution is so slow,this is a test

    yes i know,this is about apple's question,so, don't tell me answer about grandpa

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Why qt execution is so slow,this is a test

    Do you have any practical, real world problem with the performance of your Qt-based app ? Because the only comment for your test I can think of is - "so what ?"

  5. #5
    Join Date
    Feb 2012
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why qt execution is so slow,this is a test

    i just want enhance the performance of my code,i need a real about the question's answer,so please do not write some not relevant's comment.Again

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Why qt execution is so slow,this is a test

    You want to enhance the performance of appending 1000000 characters to a string ? Simple answer would be - don't do it this way. Use QString::reserve to preallocate the string buffer and then insert characters into given position, this should work faster.

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Why qt execution is so slow,this is a test

    ...or use QByteArray which shouldn't have all the UTF-8 overhead.

  8. #8
    Join Date
    Feb 2012
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why qt execution is so slow,this is a test

    thanks,i think i know that is where the problem,the string will be converted to unicode

  9. #9
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why qt execution is so slow,this is a test

    Reading the docs was helpful? No way! They are just there to look pretty.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why qt execution is so slow,this is a test

    By the way... the "C++ test" is flawed. First of all the only "C++" thing in it is using "new" and "delete" instead of "malloc" and "free" and second of all all the other "tests" increment the buffer char by char instead of preallocating everything at once.

    Here is a more proper test of this useless case and the results. If you analyze the results, you'll see what takes the most time and how to counteract it.

    text Code:
    1. ********* Start testing of StringTest *********
    2. Config: Using QTest library 4.7.4, Qt 4.7.4
    3. PASS : StringTest::initTestCase()
    4. RESULT : StringTest::testC():
    5. 16 msecs per iteration (total: 66, iterations: 4)
    6. PASS : StringTest::testC()
    7. RESULT : StringTest::testCPreallocated():
    8. 0.60 msecs per iteration (total: 77, iterations: 128)
    9. PASS : StringTest::testCPreallocated()
    10. RESULT : StringTest::testCPP():
    11. 112,716 msecs per iteration (total: 112,716, iterations: 1)
    12. PASS : StringTest::testCPP()
    13. RESULT : StringTest::testCPPPreallocated():
    14. 0.63 msecs per iteration (total: 81, iterations: 128)
    15. PASS : StringTest::testCPPPreallocated()
    16. RESULT : StringTest::testCPPString():
    17. 4.3 msecs per iteration (total: 70, iterations: 16)
    18. PASS : StringTest::testCPPString()
    19. RESULT : StringTest::testByteArray():
    20. 5.8 msecs per iteration (total: 94, iterations: 16)
    21. PASS : StringTest::testByteArray()
    22. RESULT : StringTest::testByteArrayPreallocated():
    23. 2.7 msecs per iteration (total: 89, iterations: 32)
    24. PASS : StringTest::testByteArrayPreallocated()
    25. RESULT : StringTest::testByteArrayPrefilled():
    26. 0.11 msecs per iteration (total: 60, iterations: 512)
    27. PASS : StringTest::testByteArrayPrefilled()
    28. RESULT : StringTest::testQString():
    29. 10 msecs per iteration (total: 80, iterations: 8)
    30. PASS : StringTest::testQString()
    31. RESULT : StringTest::testQStringPreallocated_reserve():
    32. 9.3 msecs per iteration (total: 75, iterations: 8)
    33. PASS : StringTest::testQStringPreallocated_reserve()
    34. RESULT : StringTest::testQStringPreallocated_resize():
    35. 7.6 msecs per iteration (total: 61, iterations: 8)
    36. PASS : StringTest::testQStringPreallocated_resize()
    37. RESULT : StringTest::testQStringPrefilled():
    38. 1.0 msecs per iteration (total: 65, iterations: 64)
    39. PASS : StringTest::testQStringPrefilled()
    40. PASS : StringTest::cleanupTestCase()
    41. Totals: 14 passed, 0 failed, 0 skipped
    42. ********* Finished testing of StringTest *********
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Lib not found in execution.
    By Netich in forum Installation and Deployment
    Replies: 6
    Last Post: 30th October 2009, 14:28
  2. RunTime Execution
    By hasnatzaidi in forum Newbie
    Replies: 3
    Last Post: 5th October 2009, 06:45
  3. execution in QT
    By adamatic in forum Qt Programming
    Replies: 4
    Last Post: 20th February 2009, 08:12
  4. Execution error
    By Shuchi Agrawal in forum Installation and Deployment
    Replies: 10
    Last Post: 9th February 2007, 12:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.