Optimization Tips
110 posts
• Page 2 of 4 • 1, 2, 3, 4
Re: Optimization TipsThat's what it's doing under the hood.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: Optimization Tips
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
Re: Optimization Tipsspeaking of each vs for :
SketchUp Ruby Consultant | Podium 1.x developer
http://plugins.ro Re: FOR .. IN
'Pick-Axe' > For ... In expressions
Re: Optimization TipsI 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
Re: Optimization TipsCame across this link:
http://www.h3rald.com/articles/efficien ... ut-review/ On that list it says
while at this link: http://www.hxa.name/articles/content/ru ... _2007.html
![]() Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: Optimization Tips
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
Re: Optimization TipsLet'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.
Re: Optimization Tips
puts "Hello World" ![]() Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: Optimization Tips
"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
Re: Optimization TipsHas anyone looked into Enumerable.grep()? it seems pretty useful, but I don't know how fast it is.
Re: Optimization Tips
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
Re: Optimization TipsThat 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
Re: Optimization TipsVertex.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). http://www.thomthom.net/blog/2010/04/sk ... rformance/ Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: Optimization TipsIts all interesting info you're digging up thomthom, but I wonder where you're going..
Ruby is a scripting language that makes for very quick development, modern constructs and good readability. So you pay for that with execution performance. However, performance with a big P which may include how fast you can complete and deliver functionality may be better - but once again I do think you should play to Ruby's strength rather than perhaps bend it into something it isn't. By the time you've created local copies of state, rewritten everything using a compact form etc etc you end up with something that is less readable and probably more prone to bugs. And as you've discovered, there is a massive difference in performance between native code and Ruby - such a large gulf, you're never going to come even close to closing it. You should do heavy lifting with a C extension and GUI / API / semantic stuff with Ruby. Processing geometry topology with Ruby is, in general, not practical. Not that it can't be done..but that's not what I'm suggesting. Developer of LightUp Click for website
Re: Optimization Tips
That was actually stuff I found out before I got around to do a C extension. Jumping from Ruby - or any other scripting language - C extensions is not an easy jump. If C isn't your cup of tea then it's worth knowing what saves time in Ruby. Most plugin writers here doesn't do C and have no interest in it either. Just making something that work - but still one can save noticeable time. What I found most interesting in those test was that Vertex is a valid argument where the manual claims only Point3d. And passing the Vertex is faster than Vertex.position. As for C extensions - it appear that there's a significant overhead of converting VALUEs to workable C types - so if you iterate only once over a set of data there isn't much to gain. Only if there's quite a bit more calculations. Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: Optimization Tips
Not really. You asked the wrong question, so you perhaps got an answer that has misled you. You asked about converting Ruby arrays to C etc. And everything I said stands. However, sounds like you actually want a C extension that operates upon the Ruby structures. If you have a situation where you are just wanting to twiddle existing Ruby data from C, it is well worth doing even for 1 pass because the fixed costs are pretty much zero. Developer of LightUp Click for website
Re: Optimization TipsI'm very green to this Ruby <-> C interaction - so its very likely I'm not doing thing the right way around.
What I have done so far is to calculate the soft selection for my Vertex Edit. So for each vertex in the selection set I needed to find the closest closest distance to any of the vertices not selected. It was the distance method that was so slow. I did some tests - created a dummy set of 3d data in C and calculated the soft selection for that. Very fast. But as soon as I made the source data set come from RUBY it became very slow. The C function was setting two sets of ruby arrays of vertices. Getting the X,Y,Z data for each vertex seemed to be very slow - converting Vertex to Point3d and then converting the X,Y,Z into C doubles. For every vertex in the selection I was iterating the remaining set of vertices and converting them. What I then did was to do a pre-pass of the non-selected vertices and create an C array of point3d structs. I then got a big speed increase. That's what lead me to the impression that converting Ruby VALUES to C types are expensive. Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: Optimization Tipsdistance requires a square root of a scalar product. ie sqrt(A.B)
Keep in mind that in native "cpu" math, A.B is perhaps ~5 cycles and sqrt(X) is perhaps ~35 cycles. If you don't actually need the squareroot but just need to find the closest, then just compare A.B which should be significantly faster. Developer of LightUp Click for website
Re: Optimization Tips
Yes - I was reading up on sqrt and found that to compare "longer" and "shorter" I didn't need sqrt. So I changed my code to only do the square root after I've found the shortest distance. That way it's called only once per vertex in Selection. (I needed the distance for some other calculations) Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: Optimization Tips
well, since no one seems to be listening... ![]() I ran my own test (for: is using a for loop, grep: is using Enumerable.grep) speedTest for: entities - 0.016 grep: entities - 0.015 for: entities array - 0.0 grep: entities array - 0.016 for: range - 0.219 grep: range - 0.203 for: range array - 0.219 grep: range array - 0.218 for: strings - 0.469 grep: strings - 0.234 nil here is the code I used:
and the model I tested on: Re: Optimization TipsI also read that depending on the settings of the compiler the instruction set used to compute sqrt and it's performance vary greatly. One of the articles I read suggested that many compilers will use old set of instructions by default for greater compatibility.
What do you do for your projects? Edit: one of the articles I read: http://assemblyrequired.crashworks.org/ ... uare-root/ Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: Optimization Tipsconcerning typename vs class:
For, till now, unexplained reason when i change typename with class the results are different Script is a bit like this:
When the type is "ComponentInstance" the results are not the same for class and typename. I need to check on this since the speed increase is huge Re: Optimization Tips.class returns a Class object - not a string.
What causes the slow down is the string comparison - that's what you want to avoid.
or
Update: fixed is_? to is_a? Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: Optimization TipsI'll check and let you know. When i use 'class' the correct conditions are entered but the result differs.
I'll keep you posted if it changes with your scripts. Thx Re: Optimization Tips![]() Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: Optimization TipsOne thing I have noticed is that some code runs much slower with the outliner window open. Is there a way to close the window at the start of certain code execution, and then re-open it at the end?
-- Karen
110 posts
• Page 2 of 4 • 1, 2, 3, 4
|
Who is online
Users browsing this forum: No registered users and 10 guests