Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defclass counter ()
- ((value :initform 0 :accessor counter-value)))
- (defgeneric m-inc (counter)
- (:method ((counter counter))
- (incf (counter-value counter))))
- (defun f-inc (counter)
- (incf (counter-value counter)))
- (defstruct s-counter
- (value 0))
- (defun s-inc (counter)
- (incf (s-counter-value counter)))
- (time (loop :with c := (make-instance 'counter)
- :repeat 1000000
- :do (m-inc c)
- :finally (return (counter-value c))))
- (time (loop :with c := (make-instance 'counter)
- :repeat 1000000
- :do (f-inc c)
- :finally (return (counter-value c))))
- (time (loop :with c := (make-s-counter)
- :repeat 1000000
- :do (s-inc c)
- :finally (return (s-counter-value c))))
- (time (loop :with c := 0
- :repeat 1000000
- :do (incf c)
- :finally (return c)))
- ;; cl-user> (load #P"~/b.lisp")
- ;; (loop :with c := (make-instance 'counter) :repeat 1000000 :do (m-inc c) :finally (return (counter-value c)))
- ;; took 106,743 microseconds (0.106743 seconds) to run.
- ;; During that period, and with 8 available CPU cores,
- ;; 92,589 microseconds (0.092589 seconds) were spent in user mode
- ;; 628 microseconds (0.000628 seconds) were spent in system mode
- ;; 1,184 bytes of memory allocated.
- ;; (loop :with c := (make-instance 'counter) :repeat 1000000 :do (f-inc c) :finally (return (counter-value c)))
- ;; took 88,853 microseconds (0.088853 seconds) to run.
- ;; During that period, and with 8 available CPU cores,
- ;; 87,517 microseconds (0.087517 seconds) were spent in user mode
- ;; 824 microseconds (0.000824 seconds) were spent in system mode
- ;; 64 bytes of memory allocated.
- ;; (loop :with c := (make-s-counter) :repeat 1000000 :do (s-inc c) :finally (return (s-counter-value c)))
- ;; took 342,449 microseconds (0.342449 seconds) to run.
- ;; During that period, and with 8 available CPU cores,
- ;; 310,990 microseconds (0.310990 seconds) were spent in user mode
- ;; 3,603 microseconds (0.003603 seconds) were spent in system mode
- ;; 32 bytes of memory allocated.
- ;; (loop :with c := 0 :repeat 1000000 :do (incf c) :finally (return c))
- ;; took 28,144 microseconds (0.028144 seconds) to run.
- ;; During that period, and with 8 available CPU cores,
- ;; 27,932 microseconds (0.027932 seconds) were spent in user mode
- ;; 74 microseconds (0.000074 seconds) were spent in system mode
- ;; #P"/Users/pjb/b.lisp"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement