Author Topic: test for object type by Is or casting...  (Read 9623 times)

0 Members and 1 Guest are viewing this topic.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: test for object type by Is or casting...
« Reply #15 on: December 19, 2009, 02:48:51 PM »
sinc it seems to me that it is too much work to just compare the ObjectClass directly in a loop, although the predimmed version is the fastest.

Glenn I can't seem to find where the direct cast is always faster, the results seem to be very close.


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: test for object type by Is or casting...
« Reply #16 on: December 19, 2009, 06:25:30 PM »

interesting results Bryce.

Thanks.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: test for object type by Is or casting...
« Reply #17 on: December 19, 2009, 06:29:08 PM »

So, at the risk of stating the obvious ;

"It depends"

on

whats is your data
what do you want to do with it
what percentage of the data do you want to do stuff to.
what mood you're in
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: test for object type by Is or casting...
« Reply #18 on: December 20, 2009, 08:44:26 AM »
D. All of the above.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: test for object type by Is or casting...
« Reply #19 on: December 20, 2009, 01:12:34 PM »
Sorry guys I messed this up.
below is a similar test but using a selectionset

Code: [Select]
            iplines = 0;
            start = DateTime.Now.Ticks;
            RXClass plineClass = RXClass.GetClass(typeof(Polyline));
            for (int i = 0; i < 10000; i++)
            {
                foreach (ObjectId id in ids)
                {
                    if (id.ObjectClass == plineClass)
                    {
                        using (Transaction tr = db.TransactionManager.StartTransaction())
                        {
                            pl = (Polyline)tr.GetObject(id, OpenMode.ForRead);
                            tr.Commit();
                            iplines++;
                        }
                    }
                }
            }

            ed.WriteMessage("\ndirect cast using pre dimmed class, ellapsed time ="
                + ((DateTime.Now.Ticks - start) / 1000).ToString()
                + " plines=" + iplines);


results
Select objects:
As test ellapsed time =25160 plines=30000
Field, ellapsed time =8340 plines=30000
direct cast using pre dimmed class, ellapsed time =8780 plines=30000
As cast using pre dimmed class, ellapsed time =8580 plines=30000
direct cast using id string comparison, ellapsed time =8940 plines=30000

Bryco

  • Water Moccasin
  • Posts: 1883
Re: test for object type by Is or casting...
« Reply #20 on: December 20, 2009, 01:24:34 PM »
I had to test before making a transaction to make it a fair test.
In this test 3 of the 10 entities were plines
So I would have to say always use the objectid method.
The field was this
public RXClass rxPolyline = RXClass.GetClass(typeof(Polyline));
and it seems to work out ok but fields are too hard to use projectwide for me, as remembering where they are is too much work.

Still, after starting w/ objectid method I have to go with Kerry's 
Quote
what mood you're in

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: test for object type by Is or casting...
« Reply #21 on: December 21, 2009, 12:50:12 AM »

Bryce,
Just a matter of interest

What is your ids collection ??

did you make an array from the Selection Set ?
        ObjectId[] idArray;
        idArray = SS.GetObjectIds();
        foreach (ObjectId id in idArray)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: test for object type by Is or casting...
« Reply #22 on: December 21, 2009, 09:51:35 AM »
I used an  ObjectIdCollection to gather the sel. set ids which is slower than what you have, but it is all before the timer starts.

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: test for object type by Is or casting...
« Reply #23 on: December 21, 2009, 12:38:32 PM »
Thx for all replies so far.
I should mention in my case, I am not only looking at acad objects.
James Maeding

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: test for object type by Is or casting...
« Reply #24 on: December 21, 2009, 04:29:06 PM »
Thx for all replies so far.
I should mention in my case, I am not only looking at acad objects.

I don't see that there would be a difference
... have you tried it ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: test for object type by Is or casting...
« Reply #25 on: December 22, 2009, 10:30:29 PM »

blatant bump attempting to get a response ....
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: test for object type by Is or casting...
« Reply #26 on: December 24, 2009, 01:55:46 PM »
right, no difference, but I cannot use ARXclass method wich seems to be pretty fast.
James Maeding

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: test for object type by Is or casting...
« Reply #27 on: December 25, 2009, 07:20:16 PM »
right, no difference, but I cannot use ARXclass method wich seems to be pretty fast.

Care to explain why you can't use it ??

What are you ACTUALLY trying to do ??
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.