(defun test-pophash (size)
(let ((table (make-hash-table:size size)))
(dotimes (i size)
(setf (gethash i table) t))
(dotimes (i size)
(pophash table))))
(time (test-pophash200000))
;; Evaluation took:;; 15.268 seconds of real time;; 15.265625 seconds of total run time (15.265625 user, 0.000000 system);; 99.99% CPU;; 38,084,922,378 processor cycles;; 5,848,704 bytes consed
たった4×105回の操作に時間が掛かりすぎである。
もちろん、次のようにremhashするだけなら計算量の問題はない。
(defun test-pophash2 (size)
(let ((table (make-hash-table:size size)))
(dotimes (i size)
(setf (gethash i table) t))
(dotimes (i size)
(remhash i table))))
(time (test-pophash2200000))
;; Evaluation took:;; 0.016 seconds of real time;; 0.015625 seconds of total run time (0.015625 user, 0.000000 system);; 100.00% CPU;; 37,052,672 processor cycles;; 5,848,704 bytes consed