Jump to content

Recommended Posts

Posted
Tharwat, the idea is good ... the problem is the cond's are adding a bit, also that you're now introducing string comparison as well, but worse the tblsearch obtains the dxf data list instead of the tblobjname which only gets the ename. As sample I've changed yours to use a T/nil flag, simplified the cond's into one or and removed all the princ's:
(defun IB:LayerOnOff (layername flag / )
 (or lays (setq lays (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object)))))
 (if (tblsearch "LAYER" layername)
   (vla-put-layeron (vla-item lays layername) (if flag :vlax-true :vlax-false))
 )
)

Yet still it's rather slow due to the tblsearch:

Benchmarking .................Elapsed milliseconds / relative speed for 16384 iteration(s):

   (LM:VLA:LAYERONOFF ACLAY "0" nil).....1844 / 3.90 <fastest>
   (AT:VLA:LAYERONOFF "0" nil)...........1922 / 3.74
   (LM:DXF:LAYERONOFF "0" nil)...........2578 / 2.79
   (IB:LAYERONOFF "0" nil)...............6375 / 1.13
   (VLAPUTLAYEROFF "0" "OFF")............7188 / 1.00 <slowest>

Yeah, that method is going to be really slow since you're checking, then extracting the layer item from the layer collection. I will not that I've seen performance (small) differences that changed me from checking existence with tblsearch to use tblobjname. Watch, someone will benchmark it and call me a liar. :P

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • irneb

    7

  • alanjt

    5

  • Lee Mac

    5

  • Bill Tillman

    2

Top Posters In This Topic

Posted

OK, I'm flabbergasted! What's the difference? After some thinking I thought it may be that if there's a number of layers the time would be different. So I now tested on a blank DWG (only Layer 0 available). My previous tests had around 40 layers in the DWG.

 

Also I'm now in Vanilla 2012 on Win7-Pro-64, i7-2600 @ 3.2GHz @ 16GB ram:

Benchmarking .................Elapsed milliseconds / relative speed for 16384 iteration(s):

   (LM:VLA:LAYERONOFF ACLAY "0" nil).....1092 / 1.09 <fastest>
   (AT:VLA:LAYERONOFF "0" nil)...........1138 / 1.04
   (LM:DXF:LAYERONOFF "0" nil)...........1186 / 1 <slowest>

Then added about 30 Layers:

Benchmarking .................Elapsed milliseconds / relative speed for 16384 iteration(s):

   (LM:DXF:LAYERONOFF "0" nil)...........1217 / 1.24 <fastest>
   (LM:VLA:LAYERONOFF ACLAY "0" nil).....1467 / 1.03
   (AT:VLA:LAYERONOFF "0" nil)...........1513 / 1 <slowest>

Then another 30 - so around 60 in total (more IMO is just "stupid"):

Benchmarking .................Elapsed milliseconds / relative speed for 16384 iteration(s):

   (AT:VLA:LAYERONOFF "0" nil)...........1202 / 1.18 <fastest>
   (LM:DXF:LAYERONOFF "0" nil)...........1217 / 1.17
   (LM:VLA:LAYERONOFF ACLAY "0" nil).....1420 / 1 <slowest>

It seems the number of Layers does have a negative effect on the dxf method, but it seems a bit random. So I upped the layer count to 120 and lo and behold:

Benchmarking .................Elapsed milliseconds / relative speed for 16384 iteration(s):

   (LM:VLA:LAYERONOFF ACLAY "0" nil).....1107 / 1.13 <fastest>
   (AT:VLA:LAYERONOFF "0" nil)...........1170 / 1.07
   (LM:DXF:LAYERONOFF "0" nil)...........1248 / 1 <slowest>

All i can think of is that the layer count has an effect. But for some reason ActiveX is much more efficient in WinXP than in Win7 (64/32 bit doesn't seem to matter). Could someone perhaps check the same on an XP64?

Posted

OK, tried again on 200 layers. This time added the defun as per my mod on Tharwat's code, but changed the tblsearch to tblobjname:

(defun IB:LayerOnOff (layername flag / )
 (or lays (setq lays (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object)))))
 (if (tblobjname "LAYER" layername)
   (vla-put-layeron (vla-item lays layername) (if flag :vlax-true :vlax-false))
 )
)

Here's the results:

Benchmarking .................Elapsed milliseconds / relative speed for 16384 iteration(s):

   (IB:LAYERONOFF "0" nil)...............1123 / 1.13 <fastest>
   (LM:VLA:LAYERONOFF ACLAY "0" nil).....1139 / 1.11
   (AT:VLA:LAYERONOFF "0" nil)...........1186 / 1.07
   (LM:DXF:LAYERONOFF "0" nil)...........1264 / 1 <slowest>

That seems to sneak past even AT's code ... which is strange since I'd think the Item method would take longer due to more layers (perhaps due to it being the 1st layer in the list), AT's is still just converting one ename to a vla-object.

 

So I tried with a layer near the end of the list:

Benchmarking .................Elapsed milliseconds / relative speed for 16384 iteration(s):

   (LM:VLA:LAYERONOFF ACLAY "Layer160" ...).....1139 / 1.11 <fastest>
   (IB:LAYERONOFF "Layer160" nil)...............1154 / 1.1
   (AT:VLA:LAYERONOFF "Layer160" nil)...........1217 / 1.04
   (LM:DXF:LAYERONOFF "Layer160" nil)...........1264 / 1 <slowest>

Still going faster!

 

Of course the differences are rather small, between 5% & 13%. Not as great as the 20% to 40% on XP.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...