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 172.5k 瀏覽 22 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • thomthomT 離線
      thomthom
      最後由 編輯

      @adamb said:

      I see a lot of SU scripts using some of the more compact iterators Ruby iterators. So they might read nice, but they're often slower than just simple for-loops.

      403 Forbidden

      favicon

      (blog.shingara.fr)

      In regard to this should one init the variables used by for in to speed up things? or is that not needed?

      Would this
      ` x = 0
      for x in collection

      ...

      endbe faster than for x in collection

      ...

      end`

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

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

        no

        Developer of LightUp Click for website

        1 條回覆 最後回覆 回覆 引用 0
        • J 離線
          Jim
          最後由 編輯

          I've always thought for used each under the hood.

          http://blog.grayproductions.net/articles/the_evils_of_the_for_loop

          for loops do not have their own scope - the loop variable and any variables created in the loop become available (or are over-written) in the current scope.

          With .each, variables are local to the block {..}

          Hi

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

            @jim said:

            I've always thought for used each under the hood.

            http://blog.grayproductions.net/articles/the_evils_of_the_for_loop

            for loops do not have their own scope - the loop variable and any variables created in the loop become available (or are over-written) in the current scope.

            If you click the method names in the Ruby API manual you get to see the sourcecode:
            http://ruby-doc.org/core/classes/Array.html#M002173

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

            1 條回覆 最後回覆 回覆 引用 0
            • J 離線
              Jim
              最後由 編輯

              That's showing a for loop in the c language.

              Hi

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

                That's what it's doing under the hood.

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

                1 條回覆 最後回覆 回覆 引用 0
                • J 離線
                  Jim
                  最後由 編輯

                  @thomthom said:

                  That's what it's doing under the hood.

                  Right, so where is the definition for the for function?

                  The answer is there isn't one because for is not a function, but is "sugar". The for loop in Ruby really uses the .each method behind the scenes.

                  Although, I can't recall where I learned that. The link to the blog article mentions it, though.

                  Hi

                  1 條回覆 最後回覆 回覆 引用 0
                  • tbdT 離線
                    tbd
                    最後由 編輯

                    speaking of each vs for :

                    loop1 = []
                    loop2 = []
                    
                    calls = ["one", "two", "three"]
                    
                    calls.each do |c|
                      loop1 << Proc.new { puts c }
                    end
                    
                    for c in calls
                      loop2 << Proc.new { puts c }
                    end
                    
                    loop1[1].call #=> "two"
                    loop2[1].call #=> "three"
                    

                    SketchUp Ruby Consultant | Podium 1.x developer
                    http://plugins.ro

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

                      @jim said:

                      The for loop in Ruby really uses the .each method behind the scenes. ... Although, I can't recall where I learned that.

                      'Pick-Axe' > For ... In expressions

                      I'm not here much anymore.

                      1 條回覆 最後回覆 回覆 引用 0
                      • J 離線
                        Jim
                        最後由 編輯

                        I guess to get back on topic, for loops are not faster then .each iterators. The performance must have to do with how the for loop variables are not loop scoped, as in each.

                        Hi

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

                          Came across this link:
                          http://www.h3rald.com/articles/efficient-ruby-code-shortcut-review/

                          On that list it says
                          @unknownuser said:

                          Use parallel assignment (a, b = 5, 6) where applicable

                          while at this link:
                          http://www.hxa.name/articles/content/ruby-speed-guide_hxa7241_2007.html

                          @unknownuser said:

                          Avoid parallel assignment

                          😒

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

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

                            @thomthom said:

                            Came across this link:
                            http://www.h3rald.com/articles/efficient-ruby-code-shortcut-review/

                            On that list it says
                            @unknownuser said:

                            Use parallel assignment (a, b = 5, 6) where applicable

                            while at this link:
                            http://www.hxa.name/articles/content/ruby-speed-guide_hxa7241_2007.html

                            @unknownuser said:

                            Avoid parallel assignment

                            😒

                            I just bought the ebook and that review summary was wrong - parallel assignments are not recommended for performance important tasks.
                            Interesting read that book btw.

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

                            1 條回覆 最後回覆 回覆 引用 0
                            • M 離線
                              MartinRinehart
                              最後由 編輯

                              Let's see - for performance I'm going to avoid iterations, arrays, hashes and objects.

                              What's left?

                              Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

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

                                @martinrinehart said:

                                What's left?

                                puts "Hello World" 😄

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

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

                                  @jim said:

                                  I guess to get back on topic, for loops are not faster then .each iterators. The performance must have to do with how the for loop variables are not loop scoped, as in each.

                                  "Your racing car is not faster than my Trabant, it just covers more ground in a shorter time than my car." 😄

                                  Developer of LightUp Click for website

                                  1 條回覆 最後回覆 回覆 引用 0
                                  • C 離線
                                    cjthompson
                                    最後由 編輯

                                    Has anyone looked into Enumerable.grep()? it seems pretty useful, but I don't know how fast it is.

                                    1 條回覆 最後回覆 回覆 引用 0
                                    • J 離線
                                      Jim
                                      最後由 編輯

                                      @adamb said:

                                      @jim said:

                                      I guess to get back on topic, for loops are not faster then .each iterators. The performance must have to do with how the for loop variables are not loop scoped, as in each.

                                      "Your racing car is not faster than my Trabant, it just covers more ground in a shorter time than my car." 😄

                                      Heh? Oh. Yes, I see. 😳

                                      Would it be correct to say: An each loop can be as fast as a for loop if the loop variable has been initialized?

                                      Hi

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

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

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

                                        1 條回覆 最後回覆 回覆 引用 0
                                        • J 離線
                                          Jim
                                          最後由 編輯

                                          Exactly.

                                          Hi

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

                                            Vertex.position is slow! Cache the result if you need to use the same Point3d multiple times.

                                            Point3d.distance also accepts Vertex objects in place of Point3d or Array.
                                            point1.distance(vertex2) is faster than point1.distance(vertex2.position).

                                            Link Preview Image
                                            Sketchup Vertex.position speed performance - ThomThom's Website

                                            favicon

                                            (www.thomthom.net)

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

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

                                            Advertisement