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:
(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.