Sketchup Vertex.position speed performance
I did some tests to investigate the performance of Vertex.position
. The test setup:
> model = Sketchup.active_model
> sel = model.selection
> v1, v2 = sel[0].vertices
> p1, p2 = v1.position, v2.position
The first tests is a simple loop repeating a million times.
> t = Time.now; 1000000.times { v1.position }; puts Time.now - t
1.351
> t = Time.now; 1000000.times { p1 }; puts Time.now - t
0.1
As you can see, the performance hit of calling Vertex.position
is significant.
> t = Time.now; 1000000.times { v1.position.distance(v2.position) }; puts Time.now - t
3.675
This is worst case scenario.
> t = Time.now; 1000000.times { v1.position.distance(v2) }; puts Time.now - t
2.705
Note that this passes a Vertex object to Point3d.distance
instead of a Point3d
object which the manual appear to indicate is the only option. As it turns out, you can pass the Vertex
object directly and gain one speed improvement.
> t = Time.now; 1000000.times { v1.position.distance(p2) }; puts Time.now - t
2.445
But it's still not as fast as using a cache variable of Vertex.position
.
> t = Time.now; 1000000.times { p1.distance(p2) }; puts Time.now - t
1.205
By far the fastest is to use only Point3d objects.
The conclusion is that you should cache the result of Vertex.position
if you will be using the position multiple times.
And if you can not cache, then remember that many functions that takes a Point3d
object as argument will also accept a vertex
object which will be faster.
Comments
No comments
Archived Posts:
Subscribe to this Blog:
Labels:
- accessibility
- animation
- api
- background-image
- barcelona
- career
- changelog
- christmas
- code
- colour
- com
- css
- deardiary
- del
- desktopx
- distance
- documentation
- dom
- england
- events
- film
- fun
- gadget
- games
- gestures
- halloween
- html
- ie
- innerhtml
- ins
- javacript
- keyboard
- life
- list-style-image
- lists
- london
- modelmaking
- moving
- msn
- paintball
- performance
- php
- pingback
- pixar
- position
- printer
- product
- ruby
- scanner
- scheme
- scripting
- semantic
- server
- sidebar
- sketchup
- skype
- snow
- software
- speed
- split()
- test
- travel
- underground
- userinterface
- vertex
- vista
- voip
- w3c
- webdesign
- website
- whitespace