-
Notifications
You must be signed in to change notification settings - Fork 14
/
bench-stripped.lisp
59 lines (48 loc) · 1.68 KB
/
bench-stripped.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
;;(ql:quickload "lparallel")
;;(ql:quickload "bordeaux-threads")
(use-package :lparallel)
(defparameter *msgbox-kernel* nil)
(defparameter *msgbox-channel* nil)
(defparameter *counter* 0)
(defparameter *called* 0)
(defparameter +threads+ 8)
(defparameter +per-thread+ 50)
(defun max-loop () (* +per-thread+ +threads+))
(format t "Times: ~a~%" (max-loop))
(defun submit-msg-sr ()
(let* ((lparallel:*kernel* *msgbox-kernel*)
(channel *msgbox-channel*))
(lparallel:submit-task channel
(lambda ()
(1+ *counter*)))
(setf *counter* (lparallel:receive-result channel))))
(defun submit-msg-fut ()
(let* ((lparallel:*kernel* *msgbox-kernel*)
(fut (lparallel:future
(incf *counter*)
*counter*)))
(force fut)))
(defun runner (submit-fun)
(setf *msgbox-kernel* (lparallel:make-kernel 1))
(let ((lparallel:*kernel* *msgbox-kernel*))
(setf *msgbox-channel* (lparallel:make-channel)))
(setf lparallel:*kernel* (lparallel:make-kernel +threads+))
(setf *counter* 0)
(unwind-protect
(time
(map nil #'lparallel:force
(mapcar (lambda (n)
(lparallel:future
(dotimes (n +per-thread+)
(funcall submit-fun))))
(loop for n from 1 to +threads+ collect n))))
(format t "Counter: ~a~%" *counter*)
(sleep 1)
(format t "Counter: ~a~%" *counter*)
(lparallel:end-kernel :wait t)
(let ((lparallel:*kernel* *msgbox-kernel*))
(lparallel:end-kernel :wait t))))
(defun runner-sr ()
(runner #'submit-msg-sr))
(defun runner-fut ()
(runner #'submit-msg-fut))