sketchucation logo sketchucation
    • 登入
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🔌 Smart Spline | Fluid way to handle splines for furniture design and complex structures. Download

    Optimization Tips

    已排程 已置頂 已鎖定 已移動 Developers' Forum
    110 貼文 22 Posters 175.4k 瀏覽 22 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • thomthomT 離線
      thomthom
      最後由 編輯

      ` t=Time.now; 1000000.times{ 3**2 }; puts Time.now - t
      0.948
      nil

      t=Time.now; 1000000.times{ 3*3 }; puts Time.now - t
      0.216
      nil`

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 條回覆 最後回覆 回覆 引用 0
      • thomthomT 離線
        thomthom
        最後由 編輯

        @unknownuser said:

        does the whole line have to be in c? im trying to map this out---
        %(#0040FF)[]

        What do you mean? Are you making a C Extension?

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 條回覆 最後回覆 回覆 引用 0
        • thomthomT 離線
          thomthom
          最後由 編輯

          @unknownuser said:

          THOM THOM WHAT KIND OF SCRIPTING LANGUAGE IS RUBY??????? 😐

          Sorry, but I don't understand what 'kind' you mean. Can you elaborate a bit more?

          And please, do not use all caps. It's hard to read and it's considered bad manners.

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 條回覆 最後回覆 回覆 引用 0
          • Dan RathbunD 離線
            Dan Rathbun
            最後由 編輯

            Ruby is a 100% Object-Oriented Interpreted Scripting Language.

            See: "Ruby Newbie's Guide to Getting Started"

            I'm not here much anymore.

            1 條回覆 最後回覆 回覆 引用 0
            • Dan RathbunD 離線
              Dan Rathbun
              最後由 編輯

              @unknownuser said:

              does the whole line have to be in c? im trying to map this out---

              If you are new to Ruby... learn Ruby scripting, don't worry about it's C source code, you'll just confuse yourself. (The Ruby interpreter engine just happens to be written in C and compiled. You don't need to know C unless your involved with actually maintaining / updating the Ruby Core libraries. This has noting to do with using Ruby or writing Ruby scripts, or using Sketchup.)

              I'm not here much anymore.

              1 條回覆 最後回覆 回覆 引用 0
              • thomthomT 離線
                thomthom
                最後由 編輯

                i += 1 vs i = i.next

                i=0; t=Time.now; 10000000.times { i+=1 }; Time.now-t
                2.045

                i=0; t=Time.now; 10000000.times { i=i.next }; Time.now-t
                1.682

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 條回覆 最後回覆 回覆 引用 0
                • TIGT 離線
                  TIG Moderator
                  最後由 編輯

                  @thomthom said:

                  i += 1 vs i = i.next
                  i=0; t=Time.now; 10000000.times { i+=1 }; Time.now-t
                  2.045
                  i=0; t=Time.now; 10000000.times { i=i.next }; Time.now-t
                  1.682

                  So avoid i='0'; t=Time.now; 10000000.times { i.next! }; Time.now-t
                  ~8.300 😒

                  TIG

                  1 條回覆 最後回覆 回覆 引用 0
                  • thomthomT 離線
                    thomthom
                    最後由 編輯

                    @thomthom said:

                    That would mean it's not the each loop itself that's slow - but the creation of variables.

                    range = (0..10000000)

                    t=Time.now; range.each { |i| x = i + 1 }; Time.now-t
                    3.402

                    t=Time.now; x=0; range.each { |i| x = i + 1 }; Time.now-t
                    2.848

                    t=Time.now; x=0; i=0; range.each { |i| x = i + 1 }; Time.now-t
                    2.39

                    t=Time.now; for j in range; y = j + 1; end; Time.now-t
                    2.196

                    t=Time.now; y=0; for j in range; y = j + 1; end; Time.now-t
                    2.186

                    If one has to use blocks, init the variables you use inside the block first.

                    Thomas Thomassen — SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 條回覆 最後回覆 回覆 引用 0
                    • D 離線
                      dany67300
                      最後由 編輯

                      I have read all you optimisation tips and tried them, but nothing seems to change the speed creation of my objects. I'm using Sketchup 8 to create dominos described by a picture. To create the dominos, I tried the add_face method and the fill_from_mesh, but the times are exactly the same. It takes me about 2 s to create 400 pieces, and it's growing exponentially. With 600 pieces -> 7s, 1200 pcs -> 50s...
                      Is it normal to take so much time ? Each domino is created in his own group for the moment, but it doesn't change if I create them directly in my scene.

                      1 條回覆 最後回覆 回覆 引用 0
                      • TIGT 離線
                        TIG Moderator
                        最後由 編輯

                        @dany67300 said:

                        I have read all you optimization tips and tried them, but nothing seems to change the speed creation of my objects. I'm using Sketchup 8 to create dominoes described by a picture. To create the dominoes, I tried the add_face method and the fill_from_mesh, but the times are exactly the same. It takes me about 2 s to create 400 pieces, and it's growing exponentially. With 600 pieces -> 7s, 1200 pces -> 50s...
                        Is it normal to take so much time ? Each domino is created in his own group for the moment, but it doesn't change if I create them directly in my scene.

                        Since all dominoes are fixed by there number pattern, why not make the set as separate SKPs with common origins.
                        Then load them into the model when you run the script - no need to make geometry at all - and ' entities.add_instance(defn, trans)' of them as needed - the transformation used when adding determines the location and rotation.
                        Because they are each component instances you can swap one type for another as you wish - in code instance.definition=xxxx ...
                        IF you only have one simple block domino make one definition and add_instances of that multiple times... You can apply different materials separately to each instance... 🤓

                        TIG

                        1 條回覆 最後回覆 回覆 引用 0
                        • D 離線
                          dany67300
                          最後由 編輯

                          I hadn't seen that i could put a different material to each instance of a same defintion 😳
                          thanks a lot ! it works very well 😄

                          1 條回覆 最後回覆 回覆 引用 0
                          • B 離線
                            bentleykfrog
                            最後由 編輯

                            @dany67300 said:

                            It takes me about 2 s to create 400 pieces, and it's growing exponentially. With 600 pieces -> 7s, 1200 pcs -> 50s...
                            Is it normal to take so much time ? Each domino is created in his own group for the moment, but it doesn't change if I create them directly in my scene.

                            I've noticed that sketchup slows down greatly once the number of groups in the current tier is greater than 1000 on my machine. Does your script speed up if the geometry is written straight to Sketchup.active_model.entities?

                            1 條回覆 最後回覆 回覆 引用 0
                            • thomthomT 離線
                              thomthom
                              最後由 編輯

                              @bentleykfrog said:

                              @dany67300 said:

                              It takes me about 2 s to create 400 pieces, and it's growing exponentially. With 600 pieces -> 7s, 1200 pcs -> 50s...
                              Is it normal to take so much time ? Each domino is created in his own group for the moment, but it doesn't change if I create them directly in my scene.

                              I've noticed that sketchup slows down greatly once the number of groups in the current tier is greater than 1000 on my machine. Does your script speed up if the geometry is written straight to Sketchup.active_model.entities?

                              Adding entities to SketchUp slows down in direct proportion to how many existing entities there is in the entities collection you add to.

                              Thomas Thomassen — SketchUp Monkey & Coding addict
                              List of my plugins and link to the CookieWare fund

                              1 條回覆 最後回覆 回覆 引用 0
                              • S 離線
                                sm4rt
                                最後由 編輯

                                Well I got a situation !! 😲

                                C:\>ruby test.rb range = (0..90000000) t=Time.now; x=0; i=0; range.each { |i| x = 0b0011_1100<<2 }; Time.now-t 13.156753 t=Time.now; x=0; i=0; range.each { |i| x = 60*4 }; Time.now-t 10.400594

                                just a no sens !!!
                                Really a human oriented language 😉

                                1 條回覆 最後回覆 回覆 引用 0
                                • Dan RathbunD 離線
                                  Dan Rathbun
                                  最後由 編輯

                                  The for loop should be faster, try:

                                  ` t = Time.now
                                  for i in range do

                                  code here

                                  end
                                  puts Time.now - t`

                                  I'm not here much anymore.

                                  1 條回覆 最後回覆 回覆 引用 0
                                  • S 離線
                                    sm4rt
                                    最後由 編輯

                                    Was talking about shifting binary number is longer then the same "base 10" arithmetic operation...

                                    Which is no sense in processor calculation.
                                    Try the same comparison in ASM, C++, PHP etc. and look the result^^

                                    But in this case I think it's because x = 0b0011_1100<<2 affect the decimal number of the binary one to x variable so the number of edge clock needed is greater... IMO

                                    Edit: And for loop isn't for me Result-for-each-variables.txt
                                    here is my results of the test that ThomThom put above to prove that for loop is better then each one and that declaring variable before is faster too but it's still not true for my equipment...
                                    (Ruby 1.9.2-p180 / Windows 7 64 bit / Intel Core i3 M 350 2.27GHz)

                                    So I think that these optimizations depend of many variables....(versions of Ruby/Sketchup) Even if some will still be true in the future...

                                    1 條回覆 最後回覆 回覆 引用 0
                                    • AdamBA 離線
                                      AdamB
                                      最後由 編輯

                                      Here's another to look out for. There is a (time) cost associated with "creating" a variable, so its often faster to use variables declared outside the scope of the executing block.

                                      def doit
                                      	
                                              start = Time.now
                                      	10000.times {
                                      		c = 5
                                      		d = 5
                                      		
                                      		e = c + d
                                      	}
                                      	puts Time.now - start
                                      	
                                      	a = 0
                                      	b = 0
                                      	c = 0
                                      	start = Time.now
                                      	10000.times {
                                      		a = 5
                                      		b = 5
                                      		
                                      		c = a + b
                                      	}
                                      	puts Time.now - start
                                      
                                      end
                                      

                                      Developer of LightUp Click for website

                                      1 條回覆 最後回覆 回覆 引用 0
                                      • G 離線
                                        glro
                                        最後由 編輯

                                        @dan rathbun said:

                                        @dan rathbun said:

                                        its nice but...
                                        The code needs updating. It needs to search by ID instead.
                                        (Or have arrays of the Inspector captions in all the local versions.)

                                        Ooops.. just checked. The Outliner does not have an ID.
                                        But Jim's system call 'may' work. The window object can have a different "name" than the text displayed on the caption bar.
                                        Someone running a non-English version could test it and let us know.

                                        I run a spanish computer using french as default language, and it doesn't work...

                                        But there is a simple way to do it, using the standard line of code you mentioned, plus a messagebox

                                        result = UI.messagebox "if the outliner window is opened, close it?'", MB_YESNO
                                          if result == 6 #yes
                                        	  #close or open the outliner window
                                        		status=UI.show_inspector "Outliner"
                                        		if status==false then
                                        		  UI.show_inspector "Outliner"
                                        		end
                                         end
                                        

                                        This way, you don't toggle on the outliner window if it is not opened already, and if it is, you close it

                                        1 條回覆 最後回覆 回覆 引用 0
                                        • Dan RathbunD 離線
                                          Dan Rathbun
                                          最後由 編輯

                                          Actually we cannot close inspectors singly. Once they are open, we can only collapse or expand them.

                                          I'm not here much anymore.

                                          1 條回覆 最後回覆 回覆 引用 0
                                          • TIGT 離線
                                            TIG Moderator
                                            最後由 編輯

                                            For Windows windows only - using Win32API.so - which you'll need to 'require'...
                                            You can 'close' just one window thus:
                                            closeWindow("Outliner")
                                            where:

                                            def closeWindow(name)
                                                findWindow = Win32API.new("user32.dll","FindWindow",['P','P'],'N')
                                                pw=findWindow.call(0,name)
                                                sendMessage = Win32API.new("user32.dll","SendMessage",['N','N','N','P'],'N')
                                                sendMessage.call(pw,0x0112,0xF060,0)#CLOSES
                                            end
                                            

                                            You can check if a window is 'visible' with:

                                            def windowIsVisible?(name)
                                                findWindow = Win32API.new("user32.dll","FindWindow",['P','P'],'N')
                                                isWindowVisible= Win32API.new("user32.dll","IsWindowVisible",['P'],'N')
                                                pw=findWindow.call(0,name)
                                                return isWindowVisible.call(pw)==1 
                                            end
                                            

                                            Incidentally, the roll 'up'/'down' methods I often use are:

                                            def toggleRollUp(name)
                                                findWindow = Win32API.new("user32.dll","FindWindow",['P','P'],'N')
                                                pw=findWindow.call(0,name)
                                                sendMessage = Win32API.new("user32.dll","SendMessage",['N','N','N','P'],'N')
                                                sendMessage.call(pw,0x00a1,2,"")#WM_NCLBUTTONDOWN
                                                sendMessage.call(pw,0x0202,0,"")#WM_LBUTTONUP
                                            end
                                            def isRolledUp?(name)
                                                findWindow = Win32API.new("user32.dll","FindWindow",['P','P'],'N')
                                                getWindowRect= Win32API.new("user32.dll","GetWindowRect",['P','PP'],'N')
                                                pw=findWindow.call(0,name)
                                                data=Array.new.fill(0.chr,0..4*4).join
                                                getWindowRect.call(pw,data)
                                                rect=data.unpack("i*")
                                                #if window height is less than 90 then the window is rolledup
                                                return (rect[3]-rect[1]) < 90
                                            end
                                            

                                            ... using isRolledUp?("Outliner") to then toggleRollUp("Outliner") to roll it up if it's down etc...

                                            TIG

                                            1 條回覆 最後回覆 回覆 引用 0
                                            • 1
                                            • 2
                                            • 3
                                            • 4
                                            • 5
                                            • 6
                                            • 2 / 6
                                            • 第一個貼文
                                              最後的貼文
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement