Advertisement
Guest User

array vs ht

a guest
Feb 12th, 2022
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. (defparameter *test* (cons 0 0))
  2. (defun make-random-keys (n)
  3. (let ((keys (loop :repeat n
  4. :collect (u:kintern (gensym)))))
  5. keys))
  6.  
  7. (defun popht (keys)
  8. (let ((ht (make-hash-table :size (length keys))))
  9. (loop :for key :across keys
  10. :for i :from 0
  11. :do (setf (gethash key ht) i))
  12. ht))
  13.  
  14. (defun test (n &optional (times 1000))
  15. (let* ((list (make-random-keys n))
  16. (array (apply #'vector list))
  17. (ht (popht array))
  18. (random-list (u:randomize list)))
  19. (u:time-nogc (rplaca *test* (loop :repeat times
  20. :collect (loop :for key :in random-list
  21. :collect (gethash key ht)))))
  22. (u:time-nogc (rplacd *test* (loop :repeat times
  23. :collect (loop :for key :in random-list
  24. :collect (position key array)))))
  25. (values)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement