TA的每日心情![](source/plugin/dsu_paulsign/img/emot/kx.gif) | 开心 2024-8-31 15:58 |
---|
签到天数: 89 天 [LV.6]常住居民II
管理员
- 积分
- 3366
|
[code](defun c:test (/ N L)
(initget 7)
(setq N (fix (getreal "\n请输入数组的长度(Please Enter the number of list):")))
(setq L (GetRandList 0 N N))
(benchMark '(Msort L) "MyMergesort" 10) ;--highflybird's
(benchMark '(QuickSort L) "QuickSort" 10) ;--gile's
(benchMark '(MergeSort L) "MergeSort" 10) ;--gile's
(benchMark '(eea-sort L) "EEA-Sort" 10) ;-- ElpanovEvgeniy's
(benchMark '(vl-sort L '<) "vl-sort" 10)
)
[/code]
[code];;;============================================================
;;;测试用函数(benchMark function)
;;;============================================================
(defun Benchmark (func funName times / t0 t1 res)
(setq t0 (getvar "TDUSRTIMER"))
(repeat times
(setq res (eval func))
)
(setq t1 (* (- (getvar "TDUSRTIMER") t0) 86400))
(princ (strcat "\n\nIt takes: " (rtos t1 2 6) " Seconds by " funName))
(princ (strcat ".\nTotal times: " (itoa times)))
(princ (strcat ".\nSpeed is: " (rtos (/ t1 times) 2 6) " Seconds/times."))
;(princ "\nThe result is: ")
;(princ res)
)
;;;---------------------------------------------------------------------
;;;Definine Rand()
;;;---------------------------------------------------------------------
(defun GetRandList(a b n / str scr lst)
(setq scr (vlax-create-object "ScriptControl")) ;Create a script
(vlax-put scr 'Language "VBS")
(setq str "Randomize\nFunction Rand(x,y)\nRand=x+Rnd*(y-x)\nEnd Function")
;for randomize some features
(vlax-invoke Scr 'ExecuteStatement str) ;Execute script
(defun Rand (scr nMin nMax) ;Rand function
(vlax-invoke scr 'run "Rand" nMin nMax)
)
(repeat n
(setq lst (cons (rand scr a b) lst))
)
(vlax-release-object scr)
lst
)[/code] |
|