little benchmark: windows 8, sketchup 2013 maker, cpu 4900mq
code:
require 'benchmark'
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
arr = ent.to_a
print "sel;",sel.to_a.size," == ent;",ent.to_a.size
puts "",arr
Benchmark.bm(20) do |x|
x.report("ent.greb") { 100000.times { faces = ent.grep(Sketchup;;Edge) } }
x.report("ent.select,is_a?") { 100000.times { faces = ent.select{|e| e.is_a? Sketchup;;Edge } } }
x.report("ent.select,class") { 100000.times { faces = ent.select{|e| e.class==Sketchup;;Edge } } }
x.report("ent.each,is_a?") { 100000.times { faces=[];ent.each{|e|faces << e if e.is_a? Sketchup;;Edge} } }
x.report("ent.each,class") { 100000.times { faces=[];ent.each{|e|faces << e if e.class==Sketchup;;Edge} } }
x.report("sel.greb") { 100000.times { faces = sel.grep(Sketchup;;Edge) } }
x.report("sel.select,is_a?") { 100000.times { faces = sel.select{|e| e.is_a? Sketchup;;Edge } } }
x.report("sel.select,class") { 100000.times { faces = sel.select{|e| e.class==Sketchup;;Edge } } }
x.report("sel.each,is_a?") { 100000.times { faces=[];sel.each{|e|faces << e if e.is_a? Sketchup;;Edge} } }
x.report("sel.each,class") { 100000.times { faces=[];sel.each{|e|faces << e if e.class==Sketchup;;Edge} } }
x.report("arr.greb") { 100000.times { faces = arr.grep(Sketchup;;Edge) } }
x.report("arr.select,is_a?") { 100000.times { faces = arr.select{|e| e.is_a? Sketchup;;Edge } } }
x.report("arr.select,class") { 100000.times { faces = arr.select{|e| e.class==Sketchup;;Edge } } }
x.report("arr.each,is_a?") { 100000.times { faces=[];arr.each{|e|faces << e if e.is_a? Sketchup;;Edge} } }
x.report("arr.each,class") { 100000.times { faces=[];arr.each{|e|faces << e if e.class==Sketchup;;Edge} } }
end
result:
user system total real
ent.greb 0.672000 0.000000 0.672000 ( 0.681000)
ent.select,is_a? 1.329000 0.000000 1.329000 ( 1.328000)
ent.select,class 1.437000 0.000000 1.437000 ( 1.445000)
ent.each,is_a? 1.266000 0.000000 1.266000 ( 1.264000)
ent.each,class 1.390000 0.000000 1.390000 ( 1.391000)
sel.greb 0.657000 0.000000 0.657000 ( 0.655000)
sel.select,is_a? 1.343000 0.000000 1.343000 ( 1.330000)
sel.select,class 1.469000 0.000000 1.469000 ( 1.452000)
sel.each,is_a? 1.250000 0.000000 1.250000 ( 1.260000)
sel.each,class 1.375000 0.000000 1.375000 ( 1.386000)
arr.greb 0.391000 0.000000 0.391000 ( 0.401000)
arr.select,is_a? 0.735000 0.000000 0.735000 ( 0.740000)
arr.select,class 0.860000 0.000000 0.860000 ( 0.873000)
arr.each,is_a? 0.953000 0.000000 0.953000 ( 0.960000)
arr.each,class 1.078000 0.000000 1.078000 ( 1.090000)
data:
sel;28 == ent;28
#<Sketchup;;Edge;0x18cf0054>
#<Sketchup;;Edge;0x18cf0018>
#<Sketchup;;Edge;0x18cf0090>
#<Sketchup;;Edge;0x18ceffdc>
#<Sketchup;;Face;0x18cf00cc>
#<Sketchup;;Group;0x18ce5e4c>
#<Sketchup;;Edge;0x18eacf64>
#<Sketchup;;Edge;0x18eacfdc>
#<Sketchup;;Edge;0x18eacf28>
#<Sketchup;;Edge;0x18eacfa0>
#<Sketchup;;Face;0x18ead018>
#<Sketchup;;Edge;0x18bd1254>
#<Sketchup;;Edge;0x18bd11dc>
#<Sketchup;;Edge;0x18bd1218>
#<Sketchup;;Edge;0x18bd11a0>
#<Sketchup;;Face;0x18bd1290>
#<Sketchup;;Edge;0x18bd0bb0>
#<Sketchup;;Edge;0x18bd0b74>
#<Sketchup;;Edge;0x18bd0b38>
#<Sketchup;;Edge;0x18bd0afc>
#<Sketchup;;Face;0x18bd0bec>
#<Sketchup;;Edge;0x18bcefb8>
#<Sketchup;;Edge;0x18bcee8c>
#<Sketchup;;Edge;0x18bcef7c>
#<Sketchup;;Edge;0x18bceec8>
#<Sketchup;;Edge;0x18bcef40>
#<Sketchup;;Edge;0x18bcef04>
#<Sketchup;;Face;0x18bceff4>