Grasshopper

algorithmic modeling for Rhino

is there any speed difference for using generic list verse a type array . for example

will

List<point3d> evaluate faster than point3d[] 

or the other way around. i am just wondering for future development projects. 

Views: 1023

Replies to This Discussion

Dima, you can write
&lt; List &gt;
and it will show like this:
< List >
- Giulio
______________
giulio@mcneel.com
McNeel Europe, Barcelona
thanks, Giulio
yes the 9x was talking about non initialized lists. if you initialize the size of a list you you are loosing a big part of why lists are nice (IMO). i will test it with the stopwatch class which i use often to test my code and see if i can get similar results. even a 2x increase in speed is big which is what Giulio was getting with an initialized list.

i do not find arrays that much harder to use especially in my application.. i end up using 2d arrays all the time because i find them easy to organize data especially with surfaces and meshes where 2d arrays are very important. i normaly use arrays and brought up this discussion because i see a lot more code using List . they are very flexible but i still like good old arrays. this is why i was hoping there could be a simple conversion for 1d and 2d arrays to GH_structure.
Giulio,

nice test, but it uses DateTime.Now to measure elapsed intervals. This is not as accurate as it could be. You should consider using a System.Diagnostics.Stopwatch class as it has much better granularity.

--
David Rutten
david@mcneel.com
London, UK
Yeah true, it probably should use the Stopwatch for Grasshopper sake. I just quickly changed the Test class, not the Benchmark attribute one. The reason I believe Jon Skeet writes the test this way is because the Benchmark attribute is then .Net framework 1.1 compatible. I'll try updating it to 2.0 next time :) .

Edit: the precision turns out not to be so bad for the sake of timing this test: "Time values are measured in 100-nanosecond units called ticks" (more).

- Giulio
Just because a DateTime structure has a potential accuracy measured in 100-nanosecond intervals, doesn't mean that DateTime.Now actually returns such an accurate time.

The resolution of the DateTime.Now method has been documented at 16 milliseconds. If the code runs for a long time then of course that is more than enough in order to profile it.

--
David Rutten
david@mcneel.com
London, UK
so i thought i would simplify things because in the end we are talking about grasshopper/rhino. i created a simple C# def that creates an array and test 4 possible types Array, Initialized List, uninitialized list, and Point3dList. i filled the list with 1,000,000 points

Array test with 1,000,000 points, time = 46 ms <- 16% slower
Initialized list test with 1,000,000 points, time = 42 ms <-8% slower
Uninitialized list test with 1,000,000 points, time = 66 ms <- 37% slower
Point3dList test with 1,000,000 points, time = 39 ms < fastest

i ran the test several times and got similar results. i assume because the c# component has to go through a compiler is probably the reason Arrays are running slower than an initialized list.

i am going to compile this into a gha and see if there is any difference.

the def is attached
Attachments:
This is a test in Release mode:


I've also added garbage collection before each loop, outside timing (even though garbage collection will also influence Grasshopper's performance).
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();

- Giulio
_________________
giulio@mcneel.com
McNeel Europe, Barcelona
so the moral of the story is as long as you initialize your good.
on another note i am happy to see the performance of the Point3dList class, the Rhino.Collections is a great hybrid between arrays and lists.
Do note that the RhinoList(Of T) classes are basically exact duplicates of the List(Of T) in native DotNET. The only difference is that we (inside RhinoCommon) have access to the internal array which means that we can pass arrayed data much faster into C++. The same benefit applies to regular arrays, but not to List(Of T).

I did add a few extra functions on RhinoList that should make some operations slightly easier.

--
David Rutten
david@mcneel.com
London, UK

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service