Author Topic: Can Python replace the LISP !!  (Read 1065 times)

0 Members and 1 Guest are viewing this topic.

d2010

  • Bull Frog
  • Posts: 309
Can Python replace the LISP !!
« on: May 20, 2023, 04:54:53 AM »
Hello.
The VLisp is slow as speed.
The LISP for Python, named Hy is slow.
The Python is slow internal AutoCad.
The  app.exe with python is 30%normal without  Autocad.
The C# is normal-speed.
The C++ is good-speed.
 :grumpy:
Code: [Select]
If the speed of Python is slower that VLISP.fas
--then is not future inside Python?
LISP stands for List Processing.
Quora==As far as I can see, Hy has no discernable benefits.
 If you want to use Python, youíd just use Python.
If you want to use Lisp, there are many excellent versions, including Clojure,
Scheme, Racket and Common Lisp. Common Lisp has many
free versions, including SBCL, CCL, Portacle and community
versions of commercial software such as LispWorks
Anyway try the speed of Go or Julia?

Perhaps > Using the function (list "many-types-of-objects") decrease the speed.lsp  too much.
Alles gutes.

« Last Edit: May 20, 2023, 05:16:15 AM by d2010 »

El Jefe

  • Retired
  • Needs a day job
  • Posts: 7933
  • AKA Daniel
Re: Can Python replace the LISP !!
« Reply #1 on: May 20, 2023, 08:32:09 PM »
Interesting, I was thinking of making a test for this using Delaunator, a Delaunay triangulation routine that has been ported to Python, C# and C++, so itís a good test.

When measuring how fast these languages are with CAD, youíre really just measuring how fast these languages interoperate with ARX
 .NET, Python and lisp all interface with CAD via some sort of wrapper.

From a CAD perspective, I think Python can be as fast as .Net, or close to it.

Python https://www.theswamp.org/index.php?topic=58234.0
C# https://www.theswamp.org/index.php?topic=57121.msg606834#msg606834
C++ https://www.theswamp.org/index.php?topic=57122.msg606896#msg606896

Python wasn't designed to be a high performance language. But I think it can be a really good language for CAD since it has a TON
of external libraries
 
Retired

El Jefe

  • Retired
  • Needs a day job
  • Posts: 7933
  • AKA Daniel
Re: Can Python replace the LISP !!
« Reply #2 on: May 20, 2023, 08:42:55 PM »
I know my python skills suck

but here's an example of reading excel into a table.
in C++, you'd have to find a library and go through the hassle of compiling it
easier in .NET, but now all the libraries are moving to Core
lisp, you'd have to party on COM, about at fun as driving a F250 with a toilet bowl plunger as the gearshift.

python, just pip openpyxl and it's ready to use.

one drawback of python is deploying, users need to setup their own environment

Code - Python: [Select]
  1. from openpyxl import load_workbook
  2.  
  3. def PyRxCmd_pydoit():
  4.     try:
  5.         table = PyDb.Table()
  6.         table.setSize(22,8)
  7.         table.generateLayout()
  8.         table.setDatabaseDefaults()
  9.        
  10.         wb  = load_workbook('sample.xlsx')
  11.         sheet = wb.active
  12.         for icol in range(7):
  13.             for irow in range(20):
  14.                 val = sheet.cell(row=irow+1, column=icol+1)
  15.                 table.setTextString(irow,icol,"{}".format(val.value))
  16.            
  17.         db = PyAp.Application().docManager().curDocument().database()
  18.         model = PyDb.BlockTableRecord(db.modelSpaceId(), PyDb.OpenMode.kForWrite)
  19.         model.appendAcDbEntity(table)  
  20.        
  21.     except Exception as err:
  22.         PyRxApp.Printf(err)
  23.  
Retired

El Jefe

  • Retired
  • Needs a day job
  • Posts: 7933
  • AKA Daniel
Re: Can Python replace the LISP !!
« Reply #3 on: May 20, 2023, 08:45:15 PM »
post a lisp, and I'll measure it against Python
Retired

BIGAL

  • Swamp Rat
  • Posts: 1230
  • 40 + years of using Autocad
Re: Can Python replace the LISP !!
« Reply #4 on: May 20, 2023, 08:59:41 PM »
How fast is fast, I did a project manual version of task around 4 hours, 1st go using command for most of it about 36 minutes, current version is about 2 minutes. That includes 4 (alert "step 1 has been completed") so user can know something has been done. I could remove the alerts but at about 1.5 minutes seems still worthwhile, but compare 4 Hours.

Excel to table should be almost instant, using VL, the clue here is to turn off table regen, and turn it back on once the table is made, this is a massive change in speed, I have seen like 2 seconds v's a minute plus. (vla-put-regeneratetablesuppressed tableobj :vlax-false)

I have select a range in Excel or just get all used cells. The latter no user input.
A man who never made a mistake never made anything

El Jefe

  • Retired
  • Needs a day job
  • Posts: 7933
  • AKA Daniel
Re: Can Python replace the LISP !!
« Reply #5 on: May 20, 2023, 09:39:10 PM »
The routine I posted is instant, just reading 7 X 20 cells though

Openpyxl, operates on the .XLSX file itself, so it never launches Excel.

https://openpyxl.readthedocs.io/en/stable/ under performance shows 50 X 1000 cells in 1.14 seconds
Tables would get wonky at that size


for ranges, maybe a named range would work?
My guess is that Python vs Lisp, with COM would be about the same, and you would need to suppress table regen with both.

caveat, my wrappers are still in progress, so yeah, lisp is still faster :)
Retired

BIGAL

  • Swamp Rat
  • Posts: 1230
  • 40 + years of using Autocad
Re: Can Python replace the LISP !!
« Reply #6 on: May 21, 2023, 10:08:29 PM »
Openpyxl, operates on the .XLSX file itself, so it never launches Excel.

That is a choice you can operate on it without seeing it open.

(vla-put-visible myXL :vlax-true)
A man who never made a mistake never made anything

El Jefe

  • Retired
  • Needs a day job
  • Posts: 7933
  • AKA Daniel
Re: Can Python replace the LISP !!
« Reply #7 on: May 22, 2023, 07:17:03 AM »
Openpyxl, operates on the .XLSX file itself, so it never launches Excel.

That is a choice you can operate on it without seeing it open.

(vla-put-visible myXL :vlax-true)

Itís not the same, setting the visibility, still launches Excel in the background.
A .XLSX is a zip file containing XML parts. Rename a sample .XLSX file, change the extension and unzip it.
Inside of the folder, youíll see a bunch of .XML parts. These XML parts are documented by Microsoft.
https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet?view=openxml-2.8.1
Openpyxl directly reads the file, whereas VLA functions ask Excel to open the file, then send you the data parts you want.
Openpyxl, OpenXLSX can read millions of cell values per second, where operating via COM is probably in the thousands.
Caveat, if you need at runtime formula evaluation, then you need to use excel, if you just need the formula value, or the formula itself, Openpyxl will get you that



Retired

El Jefe

  • Retired
  • Needs a day job
  • Posts: 7933
  • AKA Daniel
Re: Can Python replace the LISP !!
« Reply #8 on: May 22, 2023, 07:45:35 AM »
here's the file I use to test the performance of my field evaluator, 450,000 cells

in python

Code - Python: [Select]
  1. from timeit import default_timer as timer
  2. from openpyxl import load_workbook
  3.  
  4. def PyRxCmd_pydoit():
  5.     try:
  6.         start = timer()
  7.         wb  = load_workbook('M:\\Dev\\Projects\\XlsxFields\\TestData\\SampleXLSFile_50000.xlsx')
  8.         sheet = wb.active
  9.    
  10.         all_rows = []
  11.         for row in sheet.rows:
  12.             all_rows.append([data.value for data in row])
  13.            
  14.         end = timer()
  15.         print(len(all_rows))
  16.         print(end - start)
  17.     except Exception as err:
  18.         PyRxApp.Printf(err)
  19.  

Quote
4.14696879999974 seconds

not in the millions, but reasonable for such a large data set ... just to give you an idea


Retired

VovKa

  • Water Moccasin
  • Posts: 1557
  • Ukraine
Re: Can Python replace the LISP !!
« Reply #9 on: May 22, 2023, 08:14:08 AM »
not in the millions, but reasonable for such a large data set ... just to give you an idea
i use ms office 2003, so i converted xlsx to xls
COM lisp read it in 3.323 seconds on my >10 years old pentium e6600

El Jefe

  • Retired
  • Needs a day job
  • Posts: 7933
  • AKA Daniel
Re: Can Python replace the LISP !!
« Reply #10 on: May 22, 2023, 08:33:39 AM »
nice!! care your post your code?
Retired

VovKa

  • Water Moccasin
  • Posts: 1557
  • Ukraine
Re: Can Python replace the LISP !!
« Reply #11 on: May 22, 2023, 09:03:03 AM »
Code: [Select]
(defun vk_Excel-GetData (FileName SheetName Range / ExcelObj IsExcelRunning IsFileOpenned BooksObj BookObj SheetsObj SheetObj CellsObj LastCellObj
OutList *error*)
  (if (and (or (and (not FileName) (setq ExcelObj (vlax-get-object "Excel.Application")) (setq IsExcelRunning t))
       (and FileName (findfile FileName) (setq ExcelObj (vlax-create-object "Excel.Application")))
   )
   (or IsExcelRunning (not (vlax-put-property ExcelObj "Visible" :vlax-false)))
   (if FileName
     (and (setq BooksObj (vlax-get-property ExcelObj "WorkBooks"))
  (not (vl-catch-all-error-p (setq BookObj (vk_CatchMethod (list BooksObj "Open" FileName nil t)))))
     )
     (and (setq BookObj (vlax-get-property ExcelObj "ActiveWorkbook")) (setq IsFileOpenned t))
   )
   (setq SheetObj (if SheetName
    (if (setq SheetsObj (vlax-get-property BookObj "Sheets"))
      (vlax-get-property SheetsObj "Item" SheetName)
    )
    (vlax-get-property BookObj "ActiveSheet")
  )
   )
   (or Range (setq CellsObj (vlax-get-property SheetObj "UsedRange")))
      )
    (setq
      OutList (mapcar (function (lambda (row)
  (mapcar (function (lambda (cell)
      (if (setq cell (vlax-variant-change-type cell vlax-vbString))
(vlax-variant-value cell)
      )
    )
  )
  row
  )
)
      )
      (vk_VariantToLst
(vlax-get-property
  (vlax-get-property SheetObj
     "Range"
     (cond (Range)
   ((strcat "A1:"
    (vk_ExcelNumToAbc (vlax-get-property (vlax-get-property CellsObj "Columns") "Count"))
    (itoa (vlax-get-property (vlax-get-property CellsObj "Rows") "Count"))
    )
   )
     )
  )
  "Value"
)
      )
      )
    )
  )
  (foreach Obj (list (list LastCellObj)
     (list CellsObj)
     (list SheetObj)
     (list SheetsObj)
     (list BookObj
   (lambda ()
     (if (not IsFileOpenned)
       (vk_CatchMethod (list BookObj "Close" :vlax-false))
     )
   )
     )
     (list BooksObj)
     (list ExcelObj
   (lambda ()
     (if (not IsExcelRunning)
       (vk_CatchMethod (list ExcelObj "Quit"))
     )
   )
     )
       )
    (if (and (car Obj) (not (vl-catch-all-error-p (car Obj))))
      (progn (eval (cdr Obj)) (vlax-release-object (car Obj)))
    )
  )
  (gc)
  OutList
)
no dependencies because boring

El Jefe

  • Retired
  • Needs a day job
  • Posts: 7933
  • AKA Daniel
Re: Can Python replace the LISP !!
« Reply #12 on: May 22, 2023, 09:14:33 AM »
no dependencies because boring

 :lol:
Retired

El Jefe

  • Retired
  • Needs a day job
  • Posts: 7933
  • AKA Daniel
Re: Can Python replace the LISP !!
« Reply #13 on: May 22, 2023, 09:38:11 AM »
read only is
Code - Python: [Select]
  1.  wb  = load_workbook('M:\\Dev\\Projects\\XlsxFields\\TestData\\SampleXLSFile_50000.xlsx',read_only=True)

Quote
Command: PYDOIT
50000
2.3242195999991964
Retired