Created
October 2, 2021 11:32
-
-
Save fakedrake/89a6ddf22616af004010d23d29342881 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro with-repeating (threads repetitions &rest body) | |
`(mapc #'sb-thread:join-thread | |
(loop repeat ,threads | |
collect (sb-thread:make-thread | |
(lambda () (loop repeat ,repetitions do ,@body)))))) | |
(defstruct atomic-var | |
(data 0 :type (unsigned-byte 64))) | |
(proclaim '(optimize (safety 0) (speed 3))) | |
(defun increment-value () | |
(let ((x (make-atomic-var :data 0))) | |
(with-repeating 1000 1000 | |
(sb-ext:atomic-incf (atomic-var-data x) 1)) | |
x)) | |
;; The below numbers are almost identical with and without proclaim. | |
;; | |
;; CL-USER> (time (increment-value)) | |
;; Evaluation took: | |
;; 0.052 seconds of real time | |
;; 0.087489 seconds of total run time (0.059310 user, 0.028179 system) | |
;; 167.31% CPU | |
;; 908,464 bytes consed | |
;; | |
;; #S(ATOMIC-VAR :DATA 1000000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment