EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

萧闫子 发表于 2014-1-8 14:13:31

[资料] AutoCAD .NET和AutoLISP效率对比

We all know that ObjectARX and C++ are the most performing combinations for AutoCAD programming and AutoLISP may be the most time consuming one considering its interpretation design. In this article, we will put aside ObjectARX, VisualLISP, Com/ActiveX APIs aside and will talk about AutoCAD .NET and AutoLISP a bit.
Supposing we are going to create very similar 5000 simple circles with both AutoCAD .NET and AutoLISP, it is with no doubt that the .NET way is faster than AutoLISP, but how faster then?
Let’s do a small experiment to figure it out. Here is the AutoCAD .NET code as introduced before actually:
      
      public static void CreateCircles1_Method()
      {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
            DateTime begin = DateTime.Now;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord btr = tr.GetObject(bt, OpenMode.ForWrite) as BlockTableRecord;
                for (int index = 0; index < 5000; index++)
                {
                  using (Circle cir = new Circle())
                  {
                        cir.Center = new Point3d(index / 10.0, 0.0, 0.0);
                        cir.Radius = 5.0;
                        btr.AppendEntity(cir);
                        tr.AddNewlyCreatedDBObject(cir, true);
                  }
                }
                tr.Commit();
            }
            TimeSpan elapsed = DateTime.Now.Subtract(begin);
            ed.WriteMessage("Time elapsed in CreateCircles1: {0}\n", elapsed.TotalMilliseconds);
      }
Here is the AutoLISP version to create almost the same 5000 circles:
(defun C:CreateCirclesWithLISP ()
(setq time0 (getvar "cdate"))
(setq i 0)
(while (< i 5000)
    (progn
      (setq i (+ i 1))
      (entmake
'((0 . "CIRCLE")
   (10 10.0 0.0 0.0)
   (40 . 5.0)
)
      )
    )
)
(setq time1 (getvar "cdate"))
(* (- time1 time0) 10e9)
)
Here are the self-explanatory command outputs:
Command: (command "netload" "c:/temp/acadnettest.dll")
netload Assembly file name: c:/temp/acadnettest.dll
Command: nil
Command: (load "c:/temp/createcircles.lsp")
C:CREATECIRCLESWITHLISP
Command: CREATECIRCLES1
Time elapsed in CreateCircles1: 202.8004
Command: CREATECIRCLESWITHLISP
2011.66
Please note time was all expressed in milliseconds. As can be seen, the .NET command is about nine times faster than the LISP command to do pretty the same thing, which is not out of most people’s expectations.
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard)provides various project wizards, item wizards, coders and widgets to help program AutoCAD .NET addins.
页: [1]
查看完整版本: [资料] AutoCAD .NET和AutoLISP效率对比