Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. What's faster: JS comparison vs C++ bool
Forum Updated to NodeBB v4.3 + New Features

What's faster: JS comparison vs C++ bool

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 340 Views 1 Watching
  • 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.
  • SeeLookS Offline
    SeeLookS Offline
    SeeLook
    wrote on last edited by SeeLook
    #1

    Hi,
    To make this question clear enough I need to describe it more,
    but long story short at first:

    if (GlobalObject.someClass.type === SomeClass.SomeType)
    

    vs

    if (GlobalObject.someClass.someType)
    

    Which one call is better (faster, clearer, proper)?

    ... and to continue explanation:
    SomeClass is QGadget - it has to be light:

    class SomeClass
    {
      Q_GADGET
    
       Q_PROPERTY(EnumType type READ type)
       Q_PROPERTY(bool someType READ someType)
      // etc... for all enumerator types
    
    public:
      SomeClass();
      enum EnumType {
        SomeType, OtherType, YetAnotherType
      }
      Q_ENUM(EnumType)
    
      EnumType type() const { return m_type; }
    
      bool someType() const { return m_type == SomeType; }
      // etc... for all enumerator types
    
    private:
      EnumType m_type;
    }
    

    And GlobalObject is QObject derivative available in all QML code and has someClass property (member)

    Does it make any difference, what do you think?

    J.HilkJ 1 Reply Last reply
    0
    • SeeLookS SeeLook

      Hi,
      To make this question clear enough I need to describe it more,
      but long story short at first:

      if (GlobalObject.someClass.type === SomeClass.SomeType)
      

      vs

      if (GlobalObject.someClass.someType)
      

      Which one call is better (faster, clearer, proper)?

      ... and to continue explanation:
      SomeClass is QGadget - it has to be light:

      class SomeClass
      {
        Q_GADGET
      
         Q_PROPERTY(EnumType type READ type)
         Q_PROPERTY(bool someType READ someType)
        // etc... for all enumerator types
      
      public:
        SomeClass();
        enum EnumType {
          SomeType, OtherType, YetAnotherType
        }
        Q_ENUM(EnumType)
      
        EnumType type() const { return m_type; }
      
        bool someType() const { return m_type == SomeType; }
        // etc... for all enumerator types
      
      private:
        EnumType m_type;
      }
      

      And GlobalObject is QObject derivative available in all QML code and has someClass property (member)

      Does it make any difference, what do you think?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      @SeeLook hard to tell without benchmarking it

      I would say if (GlobalObject.someClass.type === SomeClass.SomeType) is slower, as the JS-Engine does not do inlining and this has 2 calls more than if (GlobalObject.someClass.someType)


      actually, modern JavaScript does indeed do inlining, huh, you learn something new every time.
      But as far as I can tell, its v8 or later and Qt is using v7 -> QML does no inlining


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • SeeLookS Offline
        SeeLookS Offline
        SeeLook
        wrote on last edited by
        #3

        @J-Hilk Thank You for the answer.

        For me if (GlobalObject.someClass.someType) is more neat as well,
        so +2 for it :-)

        1 Reply Last reply
        1
        • SeeLookS Offline
          SeeLookS Offline
          SeeLook
          wrote on last edited by
          #4

          In fact, there is one more option for this riddle:

          if (GlobalObject.someClass.type === 0) // SomeClass.SomeType
          

          and that comment is mandatory part of the code.

          It makes one call less but it is clumsy.

          1 Reply Last reply
          0

          • Login

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