Advertisement
Guest User

Untitled

a guest
Mar 28th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. (defclass counter ()
  2. ((value :initform 0 :accessor counter-value)))
  3.  
  4. (defgeneric m-inc (counter)
  5. (:method ((counter counter))
  6. (incf (counter-value counter))))
  7.  
  8. (defun f-inc (counter)
  9. (incf (counter-value counter)))
  10.  
  11. (defstruct s-counter
  12. (value 0))
  13.  
  14. (defun s-inc (counter)
  15. (incf (s-counter-value counter)))
  16.  
  17. (time (loop :with c := (make-instance 'counter)
  18. :repeat 1000000
  19. :do (m-inc c)
  20. :finally (return (counter-value c))))
  21.  
  22. (time (loop :with c := (make-instance 'counter)
  23. :repeat 1000000
  24. :do (f-inc c)
  25. :finally (return (counter-value c))))
  26.  
  27. (time (loop :with c := (make-s-counter)
  28. :repeat 1000000
  29. :do (s-inc c)
  30. :finally (return (s-counter-value c))))
  31.  
  32. (time (loop :with c := 0
  33. :repeat 1000000
  34. :do (incf c)
  35. :finally (return c)))
  36.  
  37. ;; cl-user> (load #P"~/b.lisp")
  38. ;; (loop :with c := (make-instance 'counter) :repeat 1000000 :do (m-inc c) :finally (return (counter-value c)))
  39. ;; took 106,743 microseconds (0.106743 seconds) to run.
  40. ;; During that period, and with 8 available CPU cores,
  41. ;; 92,589 microseconds (0.092589 seconds) were spent in user mode
  42. ;; 628 microseconds (0.000628 seconds) were spent in system mode
  43. ;; 1,184 bytes of memory allocated.
  44. ;; (loop :with c := (make-instance 'counter) :repeat 1000000 :do (f-inc c) :finally (return (counter-value c)))
  45. ;; took 88,853 microseconds (0.088853 seconds) to run.
  46. ;; During that period, and with 8 available CPU cores,
  47. ;; 87,517 microseconds (0.087517 seconds) were spent in user mode
  48. ;; 824 microseconds (0.000824 seconds) were spent in system mode
  49. ;; 64 bytes of memory allocated.
  50. ;; (loop :with c := (make-s-counter) :repeat 1000000 :do (s-inc c) :finally (return (s-counter-value c)))
  51. ;; took 342,449 microseconds (0.342449 seconds) to run.
  52. ;; During that period, and with 8 available CPU cores,
  53. ;; 310,990 microseconds (0.310990 seconds) were spent in user mode
  54. ;; 3,603 microseconds (0.003603 seconds) were spent in system mode
  55. ;; 32 bytes of memory allocated.
  56. ;; (loop :with c := 0 :repeat 1000000 :do (incf c) :finally (return c))
  57. ;; took 28,144 microseconds (0.028144 seconds) to run.
  58. ;; During that period, and with 8 available CPU cores,
  59. ;; 27,932 microseconds (0.027932 seconds) were spent in user mode
  60. ;; 74 microseconds (0.000074 seconds) were spent in system mode
  61. ;; #P"/Users/pjb/b.lisp"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement