Author Topic: Speed up this line draw routine ..  (Read 4532 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Speed up this line draw routine ..
« Reply #15 on: June 22, 2010, 07:56:11 AM »
Kerry, in your test13 you used this
Code: [Select]
(setq TranslatedList (mapcar '(lambda (x)but this should be faster
Code: [Select]
(setq TranslatedList (mapcar (function (lambda (x)
and WHILE is faster than foreach  :-)

Thanks Alan, I'll have a play tomorrow.

Thanks guys !!!
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.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Speed up this line draw routine ..
« Reply #16 on: June 22, 2010, 08:16:54 AM »
new version, use VLA-*


Code: [Select]
(defun test_8 (l n c)
 ;;(test_8 l n)
 (setq v (trans '(0 0 1) 1 0 T)
       a (vla-addLightWeightPolyline
          (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object)))
          (vlax-make-variant
           (vlax-safearray-fill
            (vlax-make-safearray '5 (cons 0 (1- (* (length l) 2))))
            (apply (function append)
                   (mapcar '(lambda (a) ((lambda (a) (list (car a) (cadr a))) (trans a 1 v))) l)
            ) ;_  apply
           ) ;_  vlax-safearray-fill
          ) ;_  vlax-make-variant
         ) ;_  vla-addLightWeightPolyline
 ) ;_  setq
 (vla-put-layer a n)
 (vla-put-normal a (vlax-3d-point v))
 (vla-put-closed a (if (zerop c) :vlax-false :vlax-true))
 (vla-put-elevation a (caddr (trans (car l) 1 v)))
 (vla-explode a)
 (vla-delete a)
) ;_  defun
Code: [Select]
(defun kbub:drawEnPlineInUCS (vertexList layerName putClosed / DXF210 elev)
 ;; Codehimbelonga kdub 2010.06.22
 (setq DXF210 (trans '(0 0 1) 1 0 T))
 (entmakex (append (list '(0 . "LWPOLYLINE")
                         '(100 . "AcDbEntity")
                         '(100 . "AcDbPolyline")
                         (cons 90 (length vertexList))
                         (cons 70 putClosed) ; 1 closed : 0 open
                         (cons 8 layerName)
                         (cons 38 (caddr (trans (car vertexList) 1 DXF210)))
                         (cons 210 DXF210)
                   ) ;_  list
                   (mapcar '(lambda (pt) (cons 10 (trans pt 1 DXF210))) vertexList)
           ) ;_  append
 ) ;_  entmakex
) ;_  defun
(defun test_5 (l n c)
 (if (setq l (kbub:drawEnPlineInUCS l n c))
  (progn (vla-explode (vlax-ename->vla-object l)) (entdel l))
 ) ;_  if
) ;_  defun



(length l) = 5

Code: [Select]
(progn
 (setq l '((0 0 0))
       n (getvar "CLAYER")
       c 0
 ) ;_  setq
 (mapcar
  (function (lambda (a) (repeat 1 (setq l (cons (mapcar (function +) a (car l)) l)))))
  '((1 0 0) (0 1 0) (-1 0 0) (0 -1 0))
 ) ;_  mapcar
) ;_  progn
(BenchMark '((test_5 l n c) (test_8 l n c)))
;;------------------------------
Benchmarking ..............Elapsed milliseconds / relative speed for 2048 iteration(s):

    (TEST_5 L N C).....1516 / 1.48 <fastest>
    (TEST_8 L N C).....2250 / 1.00 <slowest>



(length l) = 41
Code: [Select]
(progn
 (setq l '((0 0 0))
       n (getvar "CLAYER")
       c 0
 ) ;_  setq
 (mapcar
  (function (lambda (a) (repeat 10 (setq l (cons (mapcar (function +) a (car l)) l)))))
  '((1 0 0) (0 1 0) (-1 0 0) (0 -1 0))
 ) ;_  mapcar
) ;_  progn
(BenchMark '((test_5 l n c) (test_8 l n c)))
;;------------------------------
Benchmarking ............Elapsed milliseconds / relative speed for 512 iteration(s):

    (TEST_5 L N C).....1141 / 1.06 <fastest>
    (TEST_8 L N C).....1204 / 1.00 <slowest>




(length l) = 201
Code: [Select]
(progn
 (setq l '((0 0 0))
       n (getvar "CLAYER")
       c 0
 ) ;_  setq
 (mapcar
  (function (lambda (a) (repeat 50 (setq l (cons (mapcar (function +) a (car l)) l)))))
  '((1 0 0) (0 1 0) (-1 0 0) (0 -1 0))
 ) ;_  mapcar
) ;_  progn
(BenchMark '((test_5 l n c) (test_8 l n c)))
;;------------------------------
Benchmarking ..........Elapsed milliseconds / relative speed for 128 iteration(s):

    (TEST_8 L N C).....1078 / 1.29 <fastest>
    (TEST_5 L N C).....1391 / 1.00 <slowest>



(length l) = 2001
Code: [Select]
(progn
 (setq l '((0 0 0))
       n (getvar "CLAYER")
       c 0
 ) ;_  setq
 (mapcar
  (function (lambda (a) (repeat 500 (setq l (cons (mapcar (function +) a (car l)) l)))))
  '((1 0 0) (0 1 0) (-1 0 0) (0 -1 0))
 ) ;_  mapcar
) ;_  progn
(BenchMark '((test_5 l n c) (test_8 l n c)))
;;------------------------------
Benchmarking .......Elapsed milliseconds / relative speed for 16 iteration(s):

    (TEST_8 L N C).....1297 / 1.33 <fastest>
    (TEST_5 L N C).....1719 / 1.00 <slowest>


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Speed up this line draw routine ..
« Reply #17 on: June 22, 2010, 08:28:35 AM »
Thanks Evgeniy , that's a lot better than I was getting out of ActiveX
...  I'll check my code tomorrow, but I think it will slows down when faced with a lot of single lines  :)
yes, I think exploding a lwpline may be the way to go.

The improvement with larger lists sort of makes sense.
« Last Edit: June 22, 2010, 08:34:47 AM by Kerry Brown »
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.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Speed up this line draw routine ..
« Reply #18 on: June 22, 2010, 08:32:00 AM »

Thanks Evgeniy , that's a lot better than I was getting out of ActiveX ... I'll check my code tomorrow :)
The improvement with larger lists sort of makes sense.

How long lists will be used - 100, 1000 or 10000? For a very long list, you can make an additional optimization.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Speed up this line draw routine ..
« Reply #19 on: June 22, 2010, 08:33:41 AM »
I think you can create a polyline with the current set of points, then transform it to explode

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Speed up this line draw routine ..
« Reply #20 on: June 22, 2010, 08:37:06 AM »
< .. >
How long lists will be used - 100, 1000 or 10000? For a very long list, you can make an additional optimization.

varies from 2 to say 50 .. usually about 12 ; for the use I have in mind at the moment
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.