Author Topic: Grid point list conversion  (Read 893 times)

0 Members and 1 Guest are viewing this topic.

wizman

  • Bull Frog
  • Posts: 269
Re: Grid point list conversion
« Reply #15 on: September 12, 2020, 12:32:35 PM »
Here's a rusty attempt:

Code: [Select]


(defun foo (a)
  (list
    (car a)
    (cadr a)
  )
)

(defun rec (w / y)
  (if (cdadr w)
    (progn
      (Setq y (foo w)
    z (cons (mapcar 'foo y)
    z
      )
      )
      (rec (mapcar 'cdr y))
      (rec (cdr w))
    )
  )
)

(defun rec2 (x / z)
  (rec x)
  (reverse
    (mapcar '(lambda (x)
       (apply 'append x)
     )
    z
    )
  )
)


(rec2 '(
("1-1" "1-2" "1-3" "1-4" "1-5" "1-6" "1-7")
("2-1" "2-2" "2-3" "2-4" "2-5" "2-6" "2-7")
("3-1" "3-2" "3-3" "3-4" "3-5" "3-6" "3-7")
("4-1" "4-2" "4-3" "4-4" "4-5" "4-6" "4-7")
       )
)

ronjonp

  • Needs a day job
  • Posts: 7168
Re: Grid point list conversion
« Reply #16 on: September 14, 2020, 12:41:07 PM »
Benchmarks
Quote
Benchmarking ..................Elapsed milliseconds / relative speed for 32768 iteration(s):

    (SQUARE L).......1921 / 8.52 <fastest>
    (_RJPFOO L)......2094 / 7.81
    (F_BRUNO L)......2984 / 5.48
    (F L)............3141 / 5.21
    (REC2 L)........13516 / 1.21
    (SUBFOO L)......16359 / 1.00 <slowest>

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

MP

  • Seagull
  • Posts: 17686
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #17 on: September 14, 2020, 01:44:09 PM »
awesome
Engineering Technologist CAD Specialist Programmer Analyst
Design Drafting Document Control Automation.
cadanalyst@fastmail.com https://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

ribarm

  • Water Moccasin
  • Posts: 2383
  • Marko Ribar, architect
Re: Grid point list conversion
« Reply #18 on: September 14, 2020, 02:24:21 PM »
I would say just "some" - on Serbian... OP haven't replied in any way saying thanks or something equal to anyone participated... I don't know are replies useful to him, but IMHO not reacting to request proposed in first post is humiliating behaviour for all that wanted to contribute... And timings of sub functions - benchmarking for this task are the least meaningful. I'd say that for a matrix 1000x1000 for normal PC it would take around 1 sec for computation with any of proposed subs... And 1000x1000 matrix is IMHO monkey bussines for any kind of situation OP may be facing in real life situation.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

MP

  • Seagull
  • Posts: 17686
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #19 on: September 14, 2020, 06:06:20 PM »
... OP haven't replied in any way saying thanks or something equal to anyone participated... I don't know are replies useful to him, but IMHO not reacting to request proposed in first post is humiliating behaviour for all that wanted to contribute ...

I don't feel humiliated but I'm assuming the OP may be engaged with matters of greater importance which could be family, job ... given his tenure here that seems probable.

Cheers.
Engineering Technologist CAD Specialist Programmer Analyst
Design Drafting Document Control Automation.
cadanalyst@fastmail.com https://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

VovKa

  • Swamp Rat
  • Posts: 1272
  • Ukraine
Re: Grid point list conversion
« Reply #20 on: September 15, 2020, 06:37:10 AM »
Benchmarks
benchmarking is tricky  :angel:

loaded from VLIDE
Code: [Select]
_$ (benchmark '((subfoo lst) (_rjpfoo lst) (f lst) (square lst) (fbru lst) (recrib lst)))
Benchmarking ..................Elapsed milliseconds / relative speed for 32768 iteration(s):

    (SQUARE LST)........1701 / 78.48 <fastest>
    (_RJPFOO LST).......2121 / 62.94
    (FBRU LST)..........2356 / 56.66
    (F LST).............2465 / 54.15
    (SUBFOO LST)........9703 / 13.76
    (RECRIB LST)......133491 / 1 <slowest>

LSP loaded from Autocad command line
Code: [Select]
Command: (load "D:\\Temp\\tmp1.lsp")
Elapsed milliseconds / relative speed for 32768 iteration(s):

    (_RJPFOO LST).......1763 / 67.88 <fastest>
    (SQUARE LST)........2247 / 53.26
    (FBRU LST)..........3510 / 34.09
    (F LST).............3807 / 31.43
    (SUBFOO LST).......18876 / 6.34
    (RECRIB LST)......119668 / 1 <slowest>

FAS loaded from Autocad command line
Code: [Select]
Command: (load "D:\\Temp\\tmp1.fas")
Elapsed milliseconds / relative speed for 32768 iteration(s):

    (_RJPFOO LST).......1077 / 125.05 <fastest>
    (FBRU LST)..........3495 / 38.53
    (F LST).............3807 / 35.38
    (SQUARE LST)........3807 / 35.38
    (SUBFOO LST).......18564 / 7.25
    (RECRIB LST)......134676 / 1 <slowest>

ronjonp

  • Needs a day job
  • Posts: 7168
Re: Grid point list conversion
« Reply #21 on: September 15, 2020, 12:54:02 PM »
Benchmarks
benchmarking is tricky  :angel:

loaded from VLIDE
Code: [Select]
_$ (benchmark '((subfoo lst) (_rjpfoo lst) (f lst) (square lst) (fbru lst) (recrib lst)))
Benchmarking ..................Elapsed milliseconds / relative speed for 32768 iteration(s):

    (SQUARE LST)........1701 / 78.48 <fastest>
    (_RJPFOO LST).......2121 / 62.94
    (FBRU LST)..........2356 / 56.66
    (F LST).............2465 / 54.15
    (SUBFOO LST)........9703 / 13.76
    (RECRIB LST)......133491 / 1 <slowest>

LSP loaded from Autocad command line
Code: [Select]
Command: (load "D:\\Temp\\tmp1.lsp")
Elapsed milliseconds / relative speed for 32768 iteration(s):

    (_RJPFOO LST).......1763 / 67.88 <fastest>
    (SQUARE LST)........2247 / 53.26
    (FBRU LST)..........3510 / 34.09
    (F LST).............3807 / 31.43
    (SUBFOO LST).......18876 / 6.34
    (RECRIB LST)......119668 / 1 <slowest>

FAS loaded from Autocad command line
Code: [Select]
Command: (load "D:\\Temp\\tmp1.fas")
Elapsed milliseconds / relative speed for 32768 iteration(s):

    (_RJPFOO LST).......1077 / 125.05 <fastest>
    (FBRU LST)..........3495 / 38.53
    (F LST).............3807 / 35.38
    (SQUARE LST)........3807 / 35.38
    (SUBFOO LST).......18564 / 7.25
    (RECRIB LST)......134676 / 1 <slowest>
That it is :) ... I like your numbers better   :2funny:

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

CodeDing

  • Mosquito
  • Posts: 3
Re: Grid point list conversion
« Reply #22 on: September 15, 2020, 02:24:40 PM »
I know I'm a bit late to this party but it was fun to try. so I'll post anyways.
I mainly wanted to try to create without using append.
Code: [Select]
(defun map2sqr (map / squares)
  (mapcar
    '(lambda (m1 m2)
      (mapcar
        '(lambda (c1 c2 c3 c4)
          (setq squares (cons (list c1 c2 c3 c4) squares))
        );lambda
        m1
        (cdr m1)
        m2
        (cdr m2)
      );mapcar
    );lambda
    map
    (cdr map)
  );mapcar
  (reverse squares)
);defun

ribarm

  • Water Moccasin
  • Posts: 2383
  • Marko Ribar, architect
Re: Grid point list conversion
« Reply #23 on: September 16, 2020, 07:33:25 AM »
Just to prove that benchmark for this task is wrong idea, here are results on my PC. :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:recunfoldmatrix ( / matrix-n-m rec n m ti )
  2.  
  3.   (defun matrix-n-m ( n m / nn mm itm row mat )
  4.     (setq nn 0)
  5.     (repeat n
  6.       (setq nn (1+ nn) mm 0)
  7.       (repeat m
  8.         (setq mm (1+ mm))
  9.         (setq itm (strcat (itoa nn) "-" (itoa mm)))
  10.         (setq row (cons itm row))
  11.       )
  12.       (setq mat (cons (reverse row) mat) row nil)
  13.     )
  14.     (reverse mat)
  15.   )
  16.  
  17.   (defun rec ( mat / k itm1 itm2 kk lst )
  18.     (setq k -1)
  19.     (repeat (length mat)
  20.       (setq k (1+ k))
  21.       (setq itm1
  22.         (vl-remove-if-not '(lambda ( x ) (= (length x) 2))
  23.           (mapcar '(lambda ( x ) (setq kk (if (null kk) 2 (1+ kk))) (vl-remove-if-not '(lambda ( y ) (< (- kk 3) (vl-position y (nth k mat)) kk)) (nth k mat))) (nth k mat))
  24.         )
  25.       )
  26.       (setq kk nil)
  27.       (setq itm2
  28.         (vl-remove-if-not '(lambda ( x ) (= (length x) 2))
  29.           (mapcar '(lambda ( x ) (setq kk (if (null kk) 2 (1+ kk))) (vl-remove-if-not '(lambda ( y ) (< (- kk 3) (vl-position y (nth (1+ k) mat)) kk)) (nth (1+ k) mat))) (nth (1+ k) mat))
  30.         )
  31.       )
  32.       (setq kk nil)
  33.       (setq itm (mapcar '(lambda ( a b ) (append a b)) itm1 itm2))
  34.       (setq lst (cons itm lst))
  35.     )
  36.     (apply 'append (reverse lst))
  37.   )
  38.  
  39.   (initget 7)
  40.   (setq n (getint "\nSpecify number of rows of matrix : "))
  41.   (initget 7)
  42.   (setq m (getint "\nSpecify number of columns of matrix : "))
  43.   (setq ti (car (_vl-times)))
  44.   (princ "\n")
  45.   (prin1 (rec (matrix-n-m n m)))
  46.   (princ "\n")
  47.   (prompt "\nElapsed time : ") (princ (rtos (- (car (_vl-times)) ti) 2 20)) (prompt " milliseconds...")
  48.   (princ)
  49. )
  50.  
  51. ;|
  52. Command: RECUNFOLDMATRIX
  53.  
  54. Specify number of rows of matrix : 50
  55.  
  56. Specify number of columns of matrix : 50
  57.  
  58. (("1-1" "1-2" "2-1" "2-2") ("1-2" "1-3" "2-2" "2-3") ("1-3" "1-4" "2-3" "2-4") ("1-4" "1-5" "2-4" "2-5") ("1-5" "1-6" "2-5" "2-6") ("1-6" "1-7" "2-6" "2-7") ("1-7" "1-8" "2-7" "2-8") ("1-8" "1-9" "2-8" "2-9") ("1-9" "1-10" "2-9" "2-10") ("1-10" "1-11" "2-10" "2-11") ("1-11" "1-12" "2-11" "2-12") ("1-12" "1-13" "2-12" "2-13") ("1-13" "1-14" "2-13" "2-14") ("1-14" "1-15" "2-14" "2-15") ("1-15" "1-16" "2-15" "2-16") ("1-16" "1-17" "2-16" "2-17") ("1-17" "1-18" "2-17" "2-18") ("1-18" "1-19" "2-18" "2-19") ("1-19" "1-20" "2-19" "2-20") ("1-20" "1-21" "2-20" "2-21") ("1-21" "1-22" "2-21" "2-22") ("1-22" "1-23" "2-22" "2-23") ("1-23" "1-24" "2-23" "2-24") ("1-24" "1-25" "2-24" "2-25") ("1-25" "1-26" "2-25" "2-26") ("1-26" "1-27" "2-26" "2-27") ("1-27" "1-28" "2-27" "2-28") ("1-28" "1-29" "2-28" "2-29") ("1-29" "1-30" "2-29" "2-30") ("1-30" "1-31" "2-30" "2-31") ("1-31" "1-32" "2-31" "2-32") ("1-32" "1-33" "2-32" "2-33") ("1-33" "1-34" "2-33" "2-34") ("1-34" "1-35" "2-34" "2-35") ("1-35" "1-36" "2-35" "2-36") ("1-36" "1-37" "2-36" "2-37") ("1-37" "1-38" "2-37" "2-38") ("1-38" "1-39" "2-38" "2-39") ("1-39" "1-40" "2-39" "2-40") ("1-40" "1-41" "2-40" "2-41") ("1-41" "1-42" "2-41" "2-42") ("1-42" "1-43" "2-42" "2-43") ("1-43" "1-44" "2-43" "2-44") ("1-44" "1-45" "2-44" "2-45") ("1-45" "1-46" "2-45" "2-46") ("1-46" "1-47" "2-46" "2-47") ("1-47" "1-48" "2-47" "2-48") ("1-48" "1-49" "2-48" "2-49") ("1-49" "1-50" "2-49" "2-50")
  59.  
  60. ...
  61.  
  62. ("49-1" "49-2" "50-1" "50-2") ("49-2" "49-3" "50-2" "50-3") ("49-3" "49-4" "50-3" "50-4") ("49-4" "49-5" "50-4" "50-5") ("49-5" "49-6" "50-5" "50-6") ("49-6" "49-7" "50-6" "50-7") ("49-7" "49-8" "50-7" "50-8") ("49-8" "49-9" "50-8" "50-9") ("49-9" "49-10" "50-9" "50-10") ("49-10" "49-11" "50-10" "50-11") ("49-11" "49-12" "50-11" "50-12") ("49-12" "49-13" "50-12" "50-13") ("49-13" "49-14" "50-13" "50-14") ("49-14" "49-15" "50-14" "50-15") ("49-15" "49-16" "50-15" "50-16") ("49-16" "49-17" "50-16" "50-17") ("49-17" "49-18" "50-17" "50-18") ("49-18" "49-19" "50-18" "50-19") ("49-19" "49-20" "50-19" "50-20") ("49-20" "49-21" "50-20" "50-21") ("49-21" "49-22" "50-21" "50-22") ("49-22" "49-23" "50-22" "50-23") ("49-23" "49-24" "50-23" "50-24") ("49-24" "49-25" "50-24" "50-25") ("49-25" "49-26" "50-25" "50-26") ("49-26" "49-27" "50-26" "50-27") ("49-27" "49-28" "50-27" "50-28") ("49-28" "49-29" "50-28" "50-29") ("49-29" "49-30" "50-29" "50-30") ("49-30" "49-31" "50-30" "50-31") ("49-31" "49-32" "50-31" "50-32") ("49-32" "49-33" "50-32" "50-33") ("49-33" "49-34" "50-33" "50-34") ("49-34" "49-35" "50-34" "50-35") ("49-35" "49-36" "50-35" "50-36
  63. ") ("49-36" "49-37" "50-36" "50-37") ("49-37" "49-38" "50-37" "50-38") ("49-38" "49-39" "50-38" "50-39") ("49-39" "49-40" "50-39" "50-40") ("49-40" "49-41" "50-40" "50-41") ("49-41" "49-42" "50-41" "50-42") ("49-42" "49-43" "50-42" "50-43") ("49-43" "49-44" "50-43" "50-44") ("49-44" "49-45" "50-44" "50-45") ("49-45" "49-46" "50-45" "50-46") ("49-46" "49-47" "50-46" "50-47") ("49-47" "49-48" "50-47" "50-48") ("49-48" "49-49" "50-48" "50-49") ("49-49" "49-50" "50-49" "50-50"))
  64.  
  65. Elapsed time : 1328.000000000000 milliseconds...
  66. |;
  67.  
  68. ;;; Second test : Elapsed time : 1438.000000000000 milliseconds...
  69.  

Code - Auto/Visual Lisp: [Select]
  1. (defun c:rjpfoounfoldmatrix ( / matrix-n-m rec n m ti )
  2.  
  3.   (defun matrix-n-m ( n m / nn mm itm row mat )
  4.     (setq nn 0)
  5.     (repeat n
  6.       (setq nn (1+ nn) mm 0)
  7.       (repeat m
  8.         (setq mm (1+ mm))
  9.         (setq itm (strcat (itoa nn) "-" (itoa mm)))
  10.         (setq row (cons itm row))
  11.       )
  12.       (setq mat (cons (reverse row) mat) row nil)
  13.     )
  14.     (reverse mat)
  15.   )
  16.  
  17.   (defun _rjpfoo ( l / a b r )
  18.     (while (cadr l)
  19.       (setq a (car l)
  20.             b (cadr l)
  21.             l (cdr l)
  22.       )
  23.       (while (cadr a)
  24.         (setq r (cons (list (car a) (cadr a) (car b) (cadr b)) r)
  25.               a (cdr a)
  26.               b (cdr b)
  27.         )
  28.       )
  29.     )
  30.     (reverse r)
  31.   )
  32.  
  33.   (initget 7)
  34.   (setq n (getint "\nSpecify number of rows of matrix : "))
  35.   (initget 7)
  36.   (setq m (getint "\nSpecify number of columns of matrix : "))
  37.   (setq ti (car (_vl-times)))
  38.   (princ "\n")
  39.   (prin1 (_rjpfoo (matrix-n-m n m)))
  40.   (princ "\n")
  41.   (prompt "\nElapsed time : ") (princ (rtos (- (car (_vl-times)) ti) 2 20)) (prompt " milliseconds...")
  42.   (princ)
  43. )
  44.  
  45. ;|
  46. Command: RJPFOOUNFOLDMATRIX
  47.  
  48. Specify number of rows of matrix : 50
  49.  
  50. Specify number of columns of matrix : 50
  51.  
  52. (("1-1" "1-2" "2-1" "2-2") ("1-2" "1-3" "2-2" "2-3") ("1-3" "1-4" "2-3" "2-4") ("1-4" "1-5" "2-4" "2-5") ("1-5" "1-6" "2-5" "2-6") ("1-6" "1-7" "2-6" "2-7") ("1-7" "1-8" "2-7" "2-8") ("1-8" "1-9" "2-8" "2-9") ("1-9" "1-10" "2-9" "2-10") ("1-10" "1-11" "2-10" "2-11") ("1-11" "1-12" "2-11" "2-12") ("1-12" "1-13" "2-12" "2-13") ("1-13" "1-14" "2-13" "2-14") ("1-14" "1-15" "2-14" "2-15") ("1-15" "1-16" "2-15" "2-16") ("1-16" "1-17" "2-16" "2-17") ("1-17" "1-18" "2-17" "2-18") ("1-18" "1-19" "2-18" "2-19") ("1-19" "1-20" "2-19" "2-20") ("1-20" "1-21" "2-20" "2-21") ("1-21" "1-22" "2-21" "2-22") ("1-22" "1-23" "2-22" "2-23") ("1-23" "1-24" "2-23" "2-24") ("1-24" "1-25" "2-24" "2-25") ("1-25" "1-26" "2-25" "2-26") ("1-26" "1-27" "2-26" "2-27") ("1-27" "1-28" "2-27" "2-28") ("1-28" "1-29" "2-28" "2-29") ("1-29" "1-30" "2-29" "2-30") ("1-30" "1-31" "2-30" "2-31") ("1-31" "1-32" "2-31" "2-32") ("1-32" "1-33" "2-32" "2-33") ("1-33" "1-34" "2-33" "2-34") ("1-34" "1-35" "2-34" "2-35") ("1-35" "1-36" "2-35" "2-36") ("1-36" "1-37" "2-36" "2-37") ("1-37" "1-38" "2-37" "2-38") ("1-38" "1-39" "2-38" "2-39") ("1-39" "1-40" "2-39" "2-40") ("1-40" "1-41" "2-40" "2-41") ("1-41" "1-42" "2-41" "2-42") ("1-42" "1-43" "2-42" "2-43") ("1-43" "1-44" "2-43" "2-44") ("1-44" "1-45" "2-44" "2-45") ("1-45" "1-46" "2-45" "2-46") ("1-46" "1-47" "2-46" "2-47") ("1-47" "1-48" "2-47" "2-48") ("1-48" "1-49" "2-48" "2-49") ("1-49" "1-50" "2-49" "2-50")
  53.  
  54. ...
  55.  
  56. ("49-1" "49-2" "50-1" "50-2") ("49-2" "49-3" "50-2" "50-3") ("49-3" "49-4" "50-3" "50-4") ("49-4" "49-5" "50-4" "50-5") ("49-5" "49-6" "50-5" "50-6") ("49-6" "49-7" "50-6" "50-7") ("49-7" "49-8" "50-7" "50-8") ("49-8" "49-9" "50-8" "50-9") ("49-9" "49-10" "50-9" "50-10") ("49-10" "49-11" "50-10" "50-11") ("49-11" "49-12" "50-11" "50-12") ("49-12" "49-13" "50-12" "50-13") ("49-13" "49-14" "50-13" "50-14") ("49-14" "49-15" "50-14" "50-15") ("49-15" "49-16" "50-15" "50-16") ("49-16" "49-17" "50-16" "50-17") ("49-17" "49-18" "50-17" "50-18") ("49-18" "49-19" "50-18" "50-19") ("49-19" "49-20" "50-19" "50-20") ("49-20" "49-21" "50-20" "50-21") ("49-21" "49-22" "50-21" "50-22") ("49-22" "49-23" "50-22" "50-23") ("49-23" "49-24" "50-23" "50-24") ("49-24" "49-25" "50-24" "50-25") ("49-25" "49-26" "50-25" "50-26") ("49-26" "49-27" "50-26" "50-27") ("49-27" "49-28" "50-27" "50-28") ("49-28" "49-29" "50-28" "50-29") ("49-29" "49-30" "50-29" "50-30") ("49-30" "49-31" "50-30" "50-31") ("49-31" "49-32" "50-31" "50-32") ("49-32" "49-33" "50-32" "50-33") ("49-33" "49-34" "50-33" "50-34") ("49-34" "49-35" "50-34" "50-35") ("49-35" "49-36" "50-35" "50-36
  57. ") ("49-36" "49-37" "50-36" "50-37") ("49-37" "49-38" "50-37" "50-38") ("49-38" "49-39" "50-38" "50-39") ("49-39" "49-40" "50-39" "50-40") ("49-40" "49-41" "50-40" "50-41") ("49-41" "49-42" "50-41" "50-42") ("49-42" "49-43" "50-42" "50-43") ("49-43" "49-44" "50-43" "50-44") ("49-44" "49-45" "50-44" "50-45") ("49-45" "49-46" "50-45" "50-46") ("49-46" "49-47" "50-46" "50-47") ("49-47" "49-48" "50-47" "50-48") ("49-48" "49-49" "50-48" "50-49") ("49-49" "49-50" "50-49" "50-50"))
  58.  
  59. Elapsed time : 3047.000000000000 milliseconds...
  60. |;
  61.  
  62. ;;; Second test : Elapsed time : 4735.000000000000 milliseconds...
  63.  

As you can see, I was perhaps wrong for 1000x1000 matrix and 1 second, but my function is indeed faster than Ron's - testing sample done at 50x50 matrix... For spacing issues, I didn't copy+pasted all return list, but only first and last summing result...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

VovKa

  • Swamp Rat
  • Posts: 1272
  • Ukraine
Re: Grid point list conversion
« Reply #24 on: September 16, 2020, 08:58:03 AM »
Just to prove that benchmark for this task is wrong idea, here are results on my PC. :
Marko, can you repeat the test without (prin1 ) ?

Stefan

  • Bull Frog
  • Posts: 238
Re: Grid point list conversion
« Reply #25 on: September 16, 2020, 09:57:10 AM »
Marko, I think you take this challenge/benchmark too serious.
« Last Edit: September 16, 2020, 03:47:20 PM by Stefan »

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1079
  • Marco
Re: Grid point list conversion
« Reply #26 on: September 16, 2020, 11:29:24 AM »
I agree with "benchmarking is tricky  :angel:", I wanted to add that it can also vary with the CAD software. Perhaps the "Bruno_F" function is worthy of evaluation ...
Code: [Select]
Benchmark.lsp | 2005 Michael Puckett | All Rights Reserved

BricsCAD V20
Elapsed milliseconds / relative speed for 524288 iteration(s):
    (BRUNO_F MLIST)......1109 / 49.51 <fastest>
    (SQUARE MLIST).......1359 / 40.4
    (VOVKA_F MLIST)......1812 / 30.3
    (_RJPFOO MLIST)......1828 / 30.04
    (MAP2SQR MLIST)......2469 / 22.24
    (SUBFOO MLIST).......5984 / 9.18
    (REC2 MLIST)........12266 / 4.48
    (MR_REC MLIST)......54906 / 1 <slowest>

Elapsed milliseconds / relative speed for 524288 iteration(s):
    (BRUNO_F MLIST).....1313 / 2.04 <fastest>
    (SQUARE MLIST)......1359 / 1.97
    (_RJPFOO MLIST).....2000 / 1.34
    (VOVKA_F MLIST).....2078 / 1.29
    (MAP2SQR MLIST).....2672 / 1 <slowest>

Elapsed milliseconds / relative speed for 524288 iteration(s):
    (BRUNO_F MLIST).....1109 / 1.65 <fastest>
    (SQUARE MLIST)......1140 / 1.6
    (VOVKA_F MLIST).....1812 / 1.01
    (_RJPFOO MLIST).....1828 / 1 <slowest>

Elapsed milliseconds / relative speed for 524288 iteration(s):
    (BRUNO_F MLIST).....1266 / 1.06 <fastest>
    (SQUARE MLIST)......1344 / 1 <slowest>
Code: [Select]
AutoCAD 2013
Elapsed milliseconds / relative speed for 32768 iteration(s):
    (_RJPFOO MLIST)......2438 / 31.63 <fastest>
    (BRUNO_F MLIST)......2766 / 27.88
    (MAP2SQR MLIST)......3031 / 25.45
    (SQUARE MLIST).......3859 / 19.99
    (VOVKA_F MLIST)......7312 / 10.55
    (REC2 MLIST)........28984 / 2.66
    (SUBFOO MLIST)......34016 / 2.27
    (MR_REC MLIST)......77125 / 1 <slowest>

Elapsed milliseconds / relative speed for 32768 iteration(s):
    (_RJPFOO MLIST).....1125 / 2.35 <fastest>
    (BRUNO_F MLIST).....1219 / 2.17
    (MAP2SQR MLIST).....1468 / 1.8
    (SQUARE MLIST)......1469 / 1.8
    (VOVKA_F MLIST).....2641 / 1 <slowest>

Elapsed milliseconds / relative speed for 32768 iteration(s):
    (_RJPFOO MLIST).....1047 / 1.39 <fastest>
    (BRUNO_F MLIST).....1203 / 1.21
    (SQUARE MLIST)......1422 / 1.02
    (MAP2SQR MLIST).....1453 / 1 <slowest>

Elapsed milliseconds / relative speed for 32768 iteration(s):
    (_RJPFOO MLIST).....1094 / 1.2 <fastest>
    (BRUNO_F MLIST).....1313 / 1 <slowest>

ronjonp

  • Needs a day job
  • Posts: 7168
Re: Grid point list conversion
« Reply #27 on: September 16, 2020, 11:58:01 AM »
Just to prove that benchmark for this task is wrong idea, here are results on my PC. :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:recunfoldmatrix ( / matrix-n-m rec n m ti )
  2.  
  3.   (defun matrix-n-m ( n m / nn mm itm row mat )
  4.     (setq nn 0)
  5.     (repeat n
  6.       (setq nn (1+ nn) mm 0)
  7.       (repeat m
  8.         (setq mm (1+ mm))
  9.         (setq itm (strcat (itoa nn) "-" (itoa mm)))
  10.         (setq row (cons itm row))
  11.       )
  12.       (setq mat (cons (reverse row) mat) row nil)
  13.     )
  14.     (reverse mat)
  15.   )
  16.  
  17.   (defun rec ( mat / k itm1 itm2 kk lst )
  18.     (setq k -1)
  19.     (repeat (length mat)
  20.       (setq k (1+ k))
  21.       (setq itm1
  22.         (vl-remove-if-not '(lambda ( x ) (= (length x) 2))
  23.           (mapcar '(lambda ( x ) (setq kk (if (null kk) 2 (1+ kk))) (vl-remove-if-not '(lambda ( y ) (< (- kk 3) (vl-position y (nth k mat)) kk)) (nth k mat))) (nth k mat))
  24.         )
  25.       )
  26.       (setq kk nil)
  27.       (setq itm2
  28.         (vl-remove-if-not '(lambda ( x ) (= (length x) 2))
  29.           (mapcar '(lambda ( x ) (setq kk (if (null kk) 2 (1+ kk))) (vl-remove-if-not '(lambda ( y ) (< (- kk 3) (vl-position y (nth (1+ k) mat)) kk)) (nth (1+ k) mat))) (nth (1+ k) mat))
  30.         )
  31.       )
  32.       (setq kk nil)
  33.       (setq itm (mapcar '(lambda ( a b ) (append a b)) itm1 itm2))
  34.       (setq lst (cons itm lst))
  35.     )
  36.     (apply 'append (reverse lst))
  37.   )
  38.  
  39.   (initget 7)
  40.   (setq n (getint "\nSpecify number of rows of matrix : "))
  41.   (initget 7)
  42.   (setq m (getint "\nSpecify number of columns of matrix : "))
  43.   (setq ti (car (_vl-times)))
  44.   (princ "\n")
  45.   (prin1 (rec (matrix-n-m n m)))
  46.   (princ "\n")
  47.   (prompt "\nElapsed time : ") (princ (rtos (- (car (_vl-times)) ti) 2 20)) (prompt " milliseconds...")
  48.   (princ)
  49. )
  50.  
  51. ;|
  52. Command: RECUNFOLDMATRIX
  53.  
  54. Specify number of rows of matrix : 50
  55.  
  56. Specify number of columns of matrix : 50
  57.  
  58. (("1-1" "1-2" "2-1" "2-2") ("1-2" "1-3" "2-2" "2-3") ("1-3" "1-4" "2-3" "2-4") ("1-4" "1-5" "2-4" "2-5") ("1-5" "1-6" "2-5" "2-6") ("1-6" "1-7" "2-6" "2-7") ("1-7" "1-8" "2-7" "2-8") ("1-8" "1-9" "2-8" "2-9") ("1-9" "1-10" "2-9" "2-10") ("1-10" "1-11" "2-10" "2-11") ("1-11" "1-12" "2-11" "2-12") ("1-12" "1-13" "2-12" "2-13") ("1-13" "1-14" "2-13" "2-14") ("1-14" "1-15" "2-14" "2-15") ("1-15" "1-16" "2-15" "2-16") ("1-16" "1-17" "2-16" "2-17") ("1-17" "1-18" "2-17" "2-18") ("1-18" "1-19" "2-18" "2-19") ("1-19" "1-20" "2-19" "2-20") ("1-20" "1-21" "2-20" "2-21") ("1-21" "1-22" "2-21" "2-22") ("1-22" "1-23" "2-22" "2-23") ("1-23" "1-24" "2-23" "2-24") ("1-24" "1-25" "2-24" "2-25") ("1-25" "1-26" "2-25" "2-26") ("1-26" "1-27" "2-26" "2-27") ("1-27" "1-28" "2-27" "2-28") ("1-28" "1-29" "2-28" "2-29") ("1-29" "1-30" "2-29" "2-30") ("1-30" "1-31" "2-30" "2-31") ("1-31" "1-32" "2-31" "2-32") ("1-32" "1-33" "2-32" "2-33") ("1-33" "1-34" "2-33" "2-34") ("1-34" "1-35" "2-34" "2-35") ("1-35" "1-36" "2-35" "2-36") ("1-36" "1-37" "2-36" "2-37") ("1-37" "1-38" "2-37" "2-38") ("1-38" "1-39" "2-38" "2-39") ("1-39" "1-40" "2-39" "2-40") ("1-40" "1-41" "2-40" "2-41") ("1-41" "1-42" "2-41" "2-42") ("1-42" "1-43" "2-42" "2-43") ("1-43" "1-44" "2-43" "2-44") ("1-44" "1-45" "2-44" "2-45") ("1-45" "1-46" "2-45" "2-46") ("1-46" "1-47" "2-46" "2-47") ("1-47" "1-48" "2-47" "2-48") ("1-48" "1-49" "2-48" "2-49") ("1-49" "1-50" "2-49" "2-50")
  59.  
  60. ...
  61.  
  62. ("49-1" "49-2" "50-1" "50-2") ("49-2" "49-3" "50-2" "50-3") ("49-3" "49-4" "50-3" "50-4") ("49-4" "49-5" "50-4" "50-5") ("49-5" "49-6" "50-5" "50-6") ("49-6" "49-7" "50-6" "50-7") ("49-7" "49-8" "50-7" "50-8") ("49-8" "49-9" "50-8" "50-9") ("49-9" "49-10" "50-9" "50-10") ("49-10" "49-11" "50-10" "50-11") ("49-11" "49-12" "50-11" "50-12") ("49-12" "49-13" "50-12" "50-13") ("49-13" "49-14" "50-13" "50-14") ("49-14" "49-15" "50-14" "50-15") ("49-15" "49-16" "50-15" "50-16") ("49-16" "49-17" "50-16" "50-17") ("49-17" "49-18" "50-17" "50-18") ("49-18" "49-19" "50-18" "50-19") ("49-19" "49-20" "50-19" "50-20") ("49-20" "49-21" "50-20" "50-21") ("49-21" "49-22" "50-21" "50-22") ("49-22" "49-23" "50-22" "50-23") ("49-23" "49-24" "50-23" "50-24") ("49-24" "49-25" "50-24" "50-25") ("49-25" "49-26" "50-25" "50-26") ("49-26" "49-27" "50-26" "50-27") ("49-27" "49-28" "50-27" "50-28") ("49-28" "49-29" "50-28" "50-29") ("49-29" "49-30" "50-29" "50-30") ("49-30" "49-31" "50-30" "50-31") ("49-31" "49-32" "50-31" "50-32") ("49-32" "49-33" "50-32" "50-33") ("49-33" "49-34" "50-33" "50-34") ("49-34" "49-35" "50-34" "50-35") ("49-35" "49-36" "50-35" "50-36
  63. ") ("49-36" "49-37" "50-36" "50-37") ("49-37" "49-38" "50-37" "50-38") ("49-38" "49-39" "50-38" "50-39") ("49-39" "49-40" "50-39" "50-40") ("49-40" "49-41" "50-40" "50-41") ("49-41" "49-42" "50-41" "50-42") ("49-42" "49-43" "50-42" "50-43") ("49-43" "49-44" "50-43" "50-44") ("49-44" "49-45" "50-44" "50-45") ("49-45" "49-46" "50-45" "50-46") ("49-46" "49-47" "50-46" "50-47") ("49-47" "49-48" "50-47" "50-48") ("49-48" "49-49" "50-48" "50-49") ("49-49" "49-50" "50-49" "50-50"))
  64.  
  65. Elapsed time : 1328.000000000000 milliseconds...
  66. |;
  67.  
  68. ;;; Second test : Elapsed time : 1438.000000000000 milliseconds...
  69.  

Code - Auto/Visual Lisp: [Select]
  1. (defun c:rjpfoounfoldmatrix ( / matrix-n-m rec n m ti )
  2.  
  3.   (defun matrix-n-m ( n m / nn mm itm row mat )
  4.     (setq nn 0)
  5.     (repeat n
  6.       (setq nn (1+ nn) mm 0)
  7.       (repeat m
  8.         (setq mm (1+ mm))
  9.         (setq itm (strcat (itoa nn) "-" (itoa mm)))
  10.         (setq row (cons itm row))
  11.       )
  12.       (setq mat (cons (reverse row) mat) row nil)
  13.     )
  14.     (reverse mat)
  15.   )
  16.  
  17.   (defun _rjpfoo ( l / a b r )
  18.     (while (cadr l)
  19.       (setq a (car l)
  20.             b (cadr l)
  21.             l (cdr l)
  22.       )
  23.       (while (cadr a)
  24.         (setq r (cons (list (car a) (cadr a) (car b) (cadr b)) r)
  25.               a (cdr a)
  26.               b (cdr b)
  27.         )
  28.       )
  29.     )
  30.     (reverse r)
  31.   )
  32.  
  33.   (initget 7)
  34.   (setq n (getint "\nSpecify number of rows of matrix : "))
  35.   (initget 7)
  36.   (setq m (getint "\nSpecify number of columns of matrix : "))
  37.   (setq ti (car (_vl-times)))
  38.   (princ "\n")
  39.   (prin1 (_rjpfoo (matrix-n-m n m)))
  40.   (princ "\n")
  41.   (prompt "\nElapsed time : ") (princ (rtos (- (car (_vl-times)) ti) 2 20)) (prompt " milliseconds...")
  42.   (princ)
  43. )
  44.  
  45. ;|
  46. Command: RJPFOOUNFOLDMATRIX
  47.  
  48. Specify number of rows of matrix : 50
  49.  
  50. Specify number of columns of matrix : 50
  51.  
  52. (("1-1" "1-2" "2-1" "2-2") ("1-2" "1-3" "2-2" "2-3") ("1-3" "1-4" "2-3" "2-4") ("1-4" "1-5" "2-4" "2-5") ("1-5" "1-6" "2-5" "2-6") ("1-6" "1-7" "2-6" "2-7") ("1-7" "1-8" "2-7" "2-8") ("1-8" "1-9" "2-8" "2-9") ("1-9" "1-10" "2-9" "2-10") ("1-10" "1-11" "2-10" "2-11") ("1-11" "1-12" "2-11" "2-12") ("1-12" "1-13" "2-12" "2-13") ("1-13" "1-14" "2-13" "2-14") ("1-14" "1-15" "2-14" "2-15") ("1-15" "1-16" "2-15" "2-16") ("1-16" "1-17" "2-16" "2-17") ("1-17" "1-18" "2-17" "2-18") ("1-18" "1-19" "2-18" "2-19") ("1-19" "1-20" "2-19" "2-20") ("1-20" "1-21" "2-20" "2-21") ("1-21" "1-22" "2-21" "2-22") ("1-22" "1-23" "2-22" "2-23") ("1-23" "1-24" "2-23" "2-24") ("1-24" "1-25" "2-24" "2-25") ("1-25" "1-26" "2-25" "2-26") ("1-26" "1-27" "2-26" "2-27") ("1-27" "1-28" "2-27" "2-28") ("1-28" "1-29" "2-28" "2-29") ("1-29" "1-30" "2-29" "2-30") ("1-30" "1-31" "2-30" "2-31") ("1-31" "1-32" "2-31" "2-32") ("1-32" "1-33" "2-32" "2-33") ("1-33" "1-34" "2-33" "2-34") ("1-34" "1-35" "2-34" "2-35") ("1-35" "1-36" "2-35" "2-36") ("1-36" "1-37" "2-36" "2-37") ("1-37" "1-38" "2-37" "2-38") ("1-38" "1-39" "2-38" "2-39") ("1-39" "1-40" "2-39" "2-40") ("1-40" "1-41" "2-40" "2-41") ("1-41" "1-42" "2-41" "2-42") ("1-42" "1-43" "2-42" "2-43") ("1-43" "1-44" "2-43" "2-44") ("1-44" "1-45" "2-44" "2-45") ("1-45" "1-46" "2-45" "2-46") ("1-46" "1-47" "2-46" "2-47") ("1-47" "1-48" "2-47" "2-48") ("1-48" "1-49" "2-48" "2-49") ("1-49" "1-50" "2-49" "2-50")
  53.  
  54. ...
  55.  
  56. ("49-1" "49-2" "50-1" "50-2") ("49-2" "49-3" "50-2" "50-3") ("49-3" "49-4" "50-3" "50-4") ("49-4" "49-5" "50-4" "50-5") ("49-5" "49-6" "50-5" "50-6") ("49-6" "49-7" "50-6" "50-7") ("49-7" "49-8" "50-7" "50-8") ("49-8" "49-9" "50-8" "50-9") ("49-9" "49-10" "50-9" "50-10") ("49-10" "49-11" "50-10" "50-11") ("49-11" "49-12" "50-11" "50-12") ("49-12" "49-13" "50-12" "50-13") ("49-13" "49-14" "50-13" "50-14") ("49-14" "49-15" "50-14" "50-15") ("49-15" "49-16" "50-15" "50-16") ("49-16" "49-17" "50-16" "50-17") ("49-17" "49-18" "50-17" "50-18") ("49-18" "49-19" "50-18" "50-19") ("49-19" "49-20" "50-19" "50-20") ("49-20" "49-21" "50-20" "50-21") ("49-21" "49-22" "50-21" "50-22") ("49-22" "49-23" "50-22" "50-23") ("49-23" "49-24" "50-23" "50-24") ("49-24" "49-25" "50-24" "50-25") ("49-25" "49-26" "50-25" "50-26") ("49-26" "49-27" "50-26" "50-27") ("49-27" "49-28" "50-27" "50-28") ("49-28" "49-29" "50-28" "50-29") ("49-29" "49-30" "50-29" "50-30") ("49-30" "49-31" "50-30" "50-31") ("49-31" "49-32" "50-31" "50-32") ("49-32" "49-33" "50-32" "50-33") ("49-33" "49-34" "50-33" "50-34") ("49-34" "49-35" "50-34" "50-35") ("49-35" "49-36" "50-35" "50-36
  57. ") ("49-36" "49-37" "50-36" "50-37") ("49-37" "49-38" "50-37" "50-38") ("49-38" "49-39" "50-38" "50-39") ("49-39" "49-40" "50-39" "50-40") ("49-40" "49-41" "50-40" "50-41") ("49-41" "49-42" "50-41" "50-42") ("49-42" "49-43" "50-42" "50-43") ("49-43" "49-44" "50-43" "50-44") ("49-44" "49-45" "50-44" "50-45") ("49-45" "49-46" "50-45" "50-46") ("49-46" "49-47" "50-46" "50-47") ("49-47" "49-48" "50-47" "50-48") ("49-48" "49-49" "50-48" "50-49") ("49-49" "49-50" "50-49" "50-50"))
  58.  
  59. Elapsed time : 3047.000000000000 milliseconds...
  60. |;
  61.  
  62. ;;; Second test : Elapsed time : 4735.000000000000 milliseconds...
  63.  

As you can see, I was perhaps wrong for 1000x1000 matrix and 1 second, but my function is indeed faster than Ron's - testing sample done at 50x50 matrix... For spacing issues, I didn't copy+pasted all return list, but only first and last summing result...

Strange .. when I run the test you created 'c:rjpfoounfoldmatrix' with 50x50 speed is waaay faster than what you posted (AutoCAD 2021)
Quote
Elapsed time : 234.0000000000000 milliseconds...

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

wizman

  • Bull Frog
  • Posts: 269
Re: Grid point list conversion
« Reply #28 on: September 16, 2020, 01:19:46 PM »
Thank you for benchmarking guys.

My nested recursion has failed in speed.  I can't even benchmark it along with your great codes.

Nonetheless, it is fun to solve and see everyone's creativity in approaching the problem.















VovKa

  • Swamp Rat
  • Posts: 1272
  • Ukraine
Re: Grid point list conversion
« Reply #29 on: September 16, 2020, 02:07:38 PM »
Strange .. when I run the test you created 'c:rjpfoounfoldmatrix' with 50x50 speed is waaay faster than what you posted (AutoCAD 2021)
Quote
Elapsed time : 234.0000000000000 milliseconds...
may i ask you the same thing, Ron?
https://www.theswamp.org/index.php?topic=56239.msg601499#msg601499