Author Topic: Remove-if ... etal  (Read 3755 times)

0 Members and 1 Guest are viewing this topic.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Remove-if ... etal
« Reply #15 on: March 12, 2009, 06:54:11 PM »
Oooops  :oops:

Thanks VovKA .. missed that


tried 3 run-throughs ..
Benchmarking [M.P. 2005] ............Elapsed milliseconds for 512 iteration(s)/ relative Timing :

    (_TEST01).....610 / 1.1152 <slowest>
    (_TEST04).....594 / 1.0859
    (_TEST02).....578 / 1.0567
    (_TEST05).....563 / 1.0293
    (_TEST03).....547 / 1
    (_TEST06).....547 / 1
    (_TEST07).....547 / 1 <fastest>

 
Benchmarking [M.P. 2005] ............Elapsed milliseconds for 512 iteration(s)/ relative Timing :

    (_TEST01).....625 / 1.1447 <slowest>
    (_TEST04).....625 / 1.1447
    (_TEST02).....578 / 1.0586
    (_TEST03).....578 / 1.0586
    (_TEST05).....563 / 1.0311
    (_TEST07).....563 / 1.0311
    (_TEST06).....546 / 1 <fastest>

 
Benchmarking [M.P. 2005] ............Elapsed milliseconds for 512 iteration(s)/ relative Timing :

    (_TEST01).....594 / 1.0859 <slowest>
    (_TEST02).....578 / 1.0567
    (_TEST04).....578 / 1.0567
    (_TEST06).....563 / 1.0293
    (_TEST03).....562 / 1.0274
    (_TEST07).....562 / 1.0274
    (_TEST05).....547 / 1 <fastest>



Copy of Michaels Benchmark routine with my mods ..
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Remove-if ... etal
« Reply #16 on: March 12, 2009, 07:14:06 PM »
These are the reworked functions, revised to RETURN the Folder List for ALL functions.
The Benchmark Test can't make up it's mind ( consistently ) which function is faster

Code: [Select]
(defun _test01 ( / Folders)
  (setq Folders (vl-remove-if (function (lambda (g) (or (= g ".") (= g ".."))))
                              (vl-directory-files bom:ParentFolder NIL -1)
                )
  ) 
)

(defun _test02 ( / Folders)
  (setq Folders
         (vl-remove ".." (vl-remove "." (vl-directory-files bom:ParentFolder NIL -1)))
  )
)

(defun _test03 ( / Folders)                                                     
  (if (= "." (car (setq Folders (vl-directory-files bom:ParentFolder NIL -1))))
    (if (= ".." (car (setq Folders (cdr Folders))))
      (setq Folders (cdr Folders))
    )
  )
  Folders
)

(defun _test04 ( / Folders)
  (setq Folders (vl-remove-if (function (lambda (g) (member g '("." ".."))))
                              (vl-directory-files bom:ParentFolder NIL -1)
                )
  )
)

(defun _test05 ( / Folders)
  (setq Folders
         (if (member ".." (setq Folders (vl-directory-files bom:ParentFolder NIL -1)))
           (cddr Folders)
           Folders
         )
  )
)

(defun _test06 ( / Folders)
  (if (= ".." (cadr (setq Folders (vl-directory-files bom:ParentFolder NIL -1))))
    (setq Folders (cddr Folders))
  )
  Folders
)

(defun _test07 ( / Folders) 
  (if (> (strlen bom:ParentFolder) 3)
    (cddr (vl-directory-files bom:ParentFolder NIL -1))
    (vl-directory-files bom:ParentFolder NIL -1)
  )
)

;; (setq bom:ParentFolder "C:\\Program Files")
(setq bom:ParentFolder "C:\\")
(benchMark '((_test01) (_test02) (_test03) (_test04) (_test05) (_test06) (_test07) ))
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Remove-if ... etal
« Reply #17 on: March 12, 2009, 07:41:44 PM »
I believe the variability of the results has more to do with the unpredictability of what the system greater is doing when you're performing I/O via the vl-directory-files in each test invocation rather than stability of the benchmark function, tho I'm not inferring it is perfect. Anyway, since that portion of the code (vl-directory-files bom:ParentFolder NIL -1) is common to all functions it would be better to store the result of such to a global variable and then use said variable in each of the functions to be tested. After all, what you're wishing to bench is the performance of the code that deals with the "." .".." entries, not the I/O that retrieves them. To wit:

Code: [Select]
(progn

    (defun _test01 ( / Folders)
      (setq Folders (vl-remove-if (function (lambda (g) (or (= g ".") (= g ".."))))
                                  _folders
                    )
      )
    )

    (defun _test02 ( / Folders)
      (setq Folders
             (vl-remove ".." (vl-remove "." _folders))
      )
    )

    (defun _test03 ( / Folders)
      (if (= "." (car (setq Folders _folders)))
        (if (= ".." (car (setq Folders (cdr Folders))))
          (setq Folders (cdr Folders))
        )
      )
      Folders
    )

    (defun _test04 ( / Folders)
      (setq Folders (vl-remove-if (function (lambda (g) (member g '("." ".."))))
                                  _folders
                    )
      )
    )

    (defun _test05 ( / Folders)
      (setq Folders
             (if (member ".." (setq Folders _folders))
               (cddr Folders)
               Folders
             )
      )
    )

    (defun _test06 ( / Folders)
      (if (= ".." (cadr (setq Folders _folders)))
        (setq Folders (cddr Folders))
      )
      Folders
    )

    (defun _test07 ( / Folders)
      (if (> (strlen bom:ParentFolder) 3)
        (cddr _folders)
        _folders
      )
    )

    ;; (setq bom:ParentFolder "C:\\Program Files")
    (setq bom:ParentFolder "C:\\")
   
    (setq _folders (vl-directory-files bom:ParentFolder NIL -1))

    (repeat 5

        (benchMark
           '(   (_test01)
                (_test02)
                (_test03)
                (_test04)
                (_test05)
                (_test06)
                (_test07)
            )
        )

    )

    (princ)

)

Result (very consistant):

Elapsed milliseconds / relative speed for 65536 iteration(s):

    (_TEST03).....1641 / 1.91 <fastest>
    (_TEST06).....1672 / 1.88
    (_TEST07).....1719 / 1.83
    (_TEST02).....1797 / 1.75
    (_TEST05).....1906 / 1.65
    (_TEST01).....2844 / 1.10
    (_TEST04).....3141 / 1.00 <slowest>

Elapsed milliseconds / relative speed for 65536 iteration(s):

    (_TEST03).....1672 / 1.88 <fastest>
    (_TEST06).....1672 / 1.88
    (_TEST07).....1703 / 1.84
    (_TEST02).....1797 / 1.75
    (_TEST05).....1891 / 1.66
    (_TEST01).....2875 / 1.09
    (_TEST04).....3141 / 1.00 <slowest>

Elapsed milliseconds / relative speed for 65536 iteration(s):

    (_TEST03).....1641 / 1.91 <fastest>
    (_TEST06).....1672 / 1.88
    (_TEST07).....1718 / 1.83
    (_TEST02).....1781 / 1.76
    (_TEST05).....1921 / 1.64
    (_TEST01).....2859 / 1.10
    (_TEST04).....3141 / 1.00 <slowest>

Elapsed milliseconds / relative speed for 65536 iteration(s):

    (_TEST03).....1656 / 1.89 <fastest>
    (_TEST06).....1656 / 1.89
    (_TEST07).....1687 / 1.85
    (_TEST02).....1781 / 1.75
    (_TEST05).....1921 / 1.63
    (_TEST01).....2829 / 1.10
    (_TEST04).....3125 / 1.00 <slowest>

Elapsed milliseconds / relative speed for 65536 iteration(s):

    (_TEST03).....1641 / 1.91 <fastest>
    (_TEST06).....1656 / 1.90
    (_TEST07).....1688 / 1.86
    (_TEST02).....1797 / 1.75
    (_TEST05).....1891 / 1.66
    (_TEST01).....2813 / 1.12
    (_TEST04).....3141 / 1.00 <slowest>

Cheers. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Remove-if ... etal
« Reply #18 on: March 12, 2009, 07:51:41 PM »

Yes Michael, I came to the same conclusion, and reworked my test code in a similar manner.
.. the discrepancy is further exacerbated by accessing a network folder, albeit on a GB system :)

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Remove-if ... etal
« Reply #19 on: March 12, 2009, 07:55:01 PM »
cool :) well I'm out-a-here, been a long day :doa:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst