Most efficient way [Ruby sollutions]
-
I start this discussion because I noticed that different ways of doing same thing give major differences in time of execution.
If this thread will be sustained, I hope that ideas which will be posted here will help us all to make more efficient codes.
Here is my first observation:
I ran this code on a model with 12800 component instances and the result was this:with this version: time for completion: 0.047
model = Sketchup.active_model ents = model.entities count = 0 t1 = Time.new ents.each do |ent| if ent.class == Sketchup;;ComponentInstance count += 1 end end t2 = Time.new dt = t2 - t1 puts 'entities parsed; ' + count.to_s puts 'time for completion; ' + dt.to_sUsing this condition: time for completion: 0.078
if ent.typename == 'ComponentInstance' count += 1 end -
Check this thread for performance info:
http://forums.sketchucation.com/viewtopic.php?f=180&t=19576#p162235I extended the test with more iterations:
http://forums.sketchucation.com/viewtopic.php?f=180&t=19576&st=0&sk=t&sd=a&start=15#p166698Basically:
Avoid.typenameas string comparison is slow..is_a?and.kind_of?is aliases of the same method, they are both fast. In theory comparing.classshould be quicker as the ruby source perform less calculations, but even with a large number of iterations there isn't much deviation from.is_a?/.kind_of?.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement