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

      @adamb said:

      OT: Any chance the forum administrator of SCF can fix the [ruby:38zsi59i]tag to not remove formatting. Formatting is a big part of understanding code, and while for regular text collapsing whitespace down to a single space might work, for code it does not.

      I think the ruby is meant for inline code. While you got the code tag for block codes. (Though I wish there was a way to expand it - I loathe internal scrollbars.)

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

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

        Interesting test Adam:

        doit 6.474 3.292 nil

        Note: I increased the number of iterations ( 10000000.times { ... })

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

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

          Didn't realise Ruby would recreate the variables for each iteration. I'd thought it'd keep them for the duration of the loop...

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

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

            Seems an arbitrary (and wrong) assumption that inline code requires removing whitespace. Why not just leave in what the author wrote rather than trying to second guess? Whatever.

            Developer of LightUp Click for website

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

              Agree - whitespace eating of ruby has bothered me as well. Will ask if it can be changed.

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

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

                @thomthom said:

                Didn't realise Ruby would recreate the variables for each iteration. I'd thought it'd keep them for the duration of the loop...

                The closure you create with curly braces is handled as a first class object and passed as an argument to the iterator. This means the scope of any variables you mention inside that block is limited to that block - it must create them each time. 😞

                Developer of LightUp Click for website

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

                  Is that why each is slow?

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

                  1 條回覆 最後回覆 回覆 引用 0
                  • GaieusG 離線
                    Gaieus
                    最後由 編輯

                    Guys, Thom asked if we can do something with these white spaces but I have to say it is most probable that we cannot. I is hard coded somewhere in the php script of the forum software and even if we could tweak that, it would be impossible to keep it through upgrades (which is very due soon anyway).

                    Is the code tag not good (apart from that scrolling annoyance)?

                    Gai...

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

                      It's ok. I just hoped there was a config UI for BBCode tags on the forum. Thought it was normal. The code tag is ok, just figured if it could be changed...

                      I don't suppose there are forum plugins that can be installed? having the code block apply syntax highlighting would be a delight for us coders. Such as this:

                      Link Preview Image
                      Google Code Archive - Long-term storage for Google Code Project Hosting.

                      favicon

                      (code.google.com)

                      http://syntaxhighlighter.googlecode.com/files/Overview01.png

                      Edit: what version of phpBB does SCF run? I'm looking at this: http://www.phpbb.com/kb/article/adding-custom-bbcodes-in-phpbb3/ from this it appear to be that it'd be a matter of setting the HTML replacement for the ruby tag to not collapse white space using CSS.

                      Replacement sample something like this:
                      <span style="white-space:pre;">{TEXT}</span>

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

                      1 條回覆 最後回覆 回覆 引用 0
                      • GaieusG 離線
                        Gaieus
                        最後由 編輯

                        I can imagine you would like that syntax highlight! I use Notepad++ and know what a difference it is!

                        Coen and Tavi should be spoken to about these things.

                        Gai...

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

                                            Advertisement