Author Topic: ( Challenge ) How fast can you convert these?  (Read 26707 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8659
  • AKA Daniel
Re: ( Challenge ) How fast can you convert these?
« Reply #60 on: December 06, 2008, 11:12:17 PM »
Doh! , Its just about identical to Kerry’s  oops   :? :-o :oops:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ( Challenge ) How fast can you convert these?
« Reply #61 on: December 07, 2008, 12:20:47 AM »
... something about great minds thinking alike comes to mind ...    :wink:  :)
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: ( Challenge ) How fast can you convert these?
« Reply #62 on: December 07, 2008, 12:21:58 AM »


... but then, there are only so many ways this beast can be tamed
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.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8659
  • AKA Daniel
Re: ( Challenge ) How fast can you convert these?
« Reply #63 on: December 07, 2008, 12:47:45 AM »


... but then, there are only so many ways this beast can be tamed

the “great minds thinking alike” is what it is.  :laugh:

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: ( Challenge ) How fast can you convert these?
« Reply #64 on: December 07, 2008, 01:38:20 PM »
Quote
“great minds thinking alike”

So do I ? :?

I tried also using a selection set (here), it seems to be a little faster : 0.5156 vs 0.5625
Speaking English as a French Frog

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8659
  • AKA Daniel
Re: ( Challenge ) How fast can you convert these?
« Reply #65 on: December 07, 2008, 01:49:26 PM »
Quote
“great minds thinking alike”

So do I ? :?

I tried also using a selection set (here), it seems to be a little faster : 0.5156 vs 0.5625

yes yes  :lol:

Bryco

  • Water Moccasin
  • Posts: 1882
Re: ( Challenge ) How fast can you convert these?
« Reply #66 on: December 07, 2008, 02:14:07 PM »
Kerry this is quite a bit faster than test2 (having adjusted yours to accept a fixed normal Vector3d normal = Vector3d.ZAxis;)

Why it should be faster, I don't know.(Perhaps the deleting process must be cleaner in its own transaction.)
Code: [Select]
    public class ConvertPoints
    {
        [AcRx.CommandMethod("Test1")]
        static public void Test1()
       
        {
            DateTime timeStart = DateTime.Now;
            Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
            Database db = HostApplicationServices.WorkingDatabase;
            DBPoint pt;
            PromptSelectionResult psr=ed.SelectAll();
            if (psr.Status != PromptStatus.OK) return;
            SelectionSet ss = psr.Value;
            ObjectIdCollection ids = new ObjectIdCollection(ss.GetObjectIds());
            Point3dCollection pts = new Point3dCollection();
            Vector3d normal = Vector3d.ZAxis;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {   
                foreach (ObjectId id in ids)
                {
                    pt = tr.GetObject(id, OpenMode.ForWrite) as DBPoint;
                    if (pt != null)
                    {
                        pts.Add(pt.Position);
                    }
                    pt.Erase();
                }
                tr.Commit();     
            }
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelspace = tr.GetObject
                    (bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                foreach (Point3d pt3d in pts)
                {
                    Circle c = new Circle(pt3d, normal, 15.0);     
                    modelspace.AppendEntity(c);
                    tr.AddNewlyCreatedDBObject(c, true);
                }
                tr.Commit();
            }

            TimeSpan TimeDuration = (DateTime.Now - timeStart);
            ed.WriteMessage("Ellapsed time: {0} seconds", (TimeDuration.TotalSeconds));
           
        }

Bryco

  • Water Moccasin
  • Posts: 1882
Re: ( Challenge ) How fast can you convert these?
« Reply #67 on: December 07, 2008, 04:52:33 PM »
That's odd the computer at work is reading
Command: TEST1 Ellapsed time: 1.7502688 seconds
Command: TEST2 Ellapsed time: 1.9065428 seconds

whereas at home it was more like 1.3 to 1.7
I've had coffee and it's too early for a beer so ???.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2120
  • class keyThumper<T>:ILazy<T>
Re: ( Challenge ) How fast can you convert these?
« Reply #68 on: December 07, 2008, 04:54:41 PM »
Thats an interesting variation Bryco.

I'd have thought the overhead of making a new collection to hold the points locations would slow it down ... deserves some more testing ...

// kerry
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2120
  • class keyThumper<T>:ILazy<T>
Re: ( Challenge ) How fast can you convert these?
« Reply #69 on: December 07, 2008, 05:01:28 PM »

... and yes, having the vector as variable instead of recalculating based on the point normal should tweek a couple more ticks from the time.

//kwb
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Bryco

  • Water Moccasin
  • Posts: 1882
Re: ( Challenge ) How fast can you convert these?
« Reply #70 on: December 07, 2008, 05:02:42 PM »
Agreed, looks like more overhead.
It's also interesting how using  if (pt != null) is actually seemed faster than making a filter for the selection set and removing the if (pt != null).
The filter must be using is.

Bryco

  • Water Moccasin
  • Posts: 1882
Re: ( Challenge ) How fast can you convert these?
« Reply #71 on: December 07, 2008, 05:06:11 PM »
Here is your test2 with apples to apples
Code: [Select]
[CommandMethod("Test2")]
        static public void Test2()
        {
            DateTime timeStart = DateTime.Now;
            Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
            Database db = HostApplicationServices.WorkingDatabase;
            Vector3d normal = Vector3d.ZAxis;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {

                BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
                                        as BlockTableRecord;
                foreach (ObjectId objId in btr)
                {                   
                    // make the assignment more direct
                    //
                    DBPoint pt = tr.GetObject(objId, OpenMode.ForWrite) as DBPoint;
                    if (pt != null)
                    {
                        Circle c = new Circle(pt.Position, normal, 15.0);
                        pt.Erase();
                        btr.AppendEntity(c);
                        tr.AddNewlyCreatedDBObject(c, true);
                    }
                }
                tr.Commit();

            }
            TimeSpan TimeDuration = (DateTime.Now - timeStart);
            ed.WriteMessage("Ellapsed time: {0} seconds", (TimeDuration.TotalSeconds ));
        }

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8659
  • AKA Daniel
Re: ( Challenge ) How fast can you convert these?
« Reply #72 on: December 08, 2008, 03:24:22 PM »
 :lol:

< Elapsed time: 32.703000 seconds.>

Code: [Select]
;;;AutoLisp
(defun c:test (/ ss *time*)
  (setq *time* (getvar 'MILLISECS))
  (L#TEST)
  (princ
    (strcat "\n < Elapsed time: "
            (rtos (/ (- (getvar 'MILLISECS) time*) 1000.0) 2 6)
            " seconds. > "
    )
  )
)
;;;L#
(def L#TEST  ()
     (= pDb (HostApplicationServices.WorkingDatabase))
     (= tm (.TransactionManager pDb))
     (= tr (.StartTransaction tm))
     (= id (SymbolUtilityServices.GetBlockModelSpaceId pDb))
     (= forWrite (OpenMode.ForWrite))
     (= forRead (OpenMode.ForRead))
     (= blockTableRecord (.GetObject tr id forWrite))
     (each e
           blockTableRecord
           (= dbo (.GetObject tr e forWrite))
           (= str(.ToString dbo))
           (if (is str "Autodesk.AutoCAD.DatabaseServices.DBPoint")
             (progn
               (= c
                  (new "Circle"
                       (.Position dbo)
                       (.Normal dbo)
                       15
                  )
               )
               (= id2(.AppendEntity blockTableRecord c))
               (.AddNewlyCreatedDBObject tr c true)
               (.Erase dbo)
             )
           )
     )
     (.Commit tr)
     (.Dispose tr)
)

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2120
  • class keyThumper<T>:ILazy<T>
Re: ( Challenge ) How fast can you convert these?
« Reply #73 on: December 08, 2008, 04:20:29 PM »
I was thinking about coding one in F# ... but real work and sleep keep getting in the way ...

//kdub
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Greg B

  • Seagull
  • Posts: 12417
  • Tell me a Joke!
Re: ( Challenge ) How fast can you convert these?
« Reply #74 on: December 08, 2008, 04:40:40 PM »
I was thinking about coding one in F# ... but real work and sleep keep getting in the way ...

//kdub

Would that be with a guitar or keyboard?