-
Notifications
You must be signed in to change notification settings - Fork 8
/
LispNoBignum.lisp
54 lines (44 loc) · 2.1 KB
/
LispNoBignum.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
(defpackage #:mem-test
(:nicknames :mt)
(:use #:cl))
(declaim (optimize (speed 3) (safety 0) (space 0) (debug 0)))
(in-package #:mem-test)
(export '(run))
(defconstant +NUM_RECORDS+ (* 50 1000 444))
(defstruct lisp-memory-trade (trade-id 0) (client-id 0) (venue-code 0) (instrument-code 0) (price 0 :type fixnum) (quantity 0 :type fixnum) (side #\x))
(declaim ((simple-array lisp-memory-trade *) trades))
(defvar trades (make-array +NUM_RECORDS+ :element-type 'lisp-memory-trade) )
(defun prep-trades ()
(dotimes (i +NUM_RECORDS+)
(setf (aref trades i) (make-lisp-memory-trade) )))
(defun init-trades ()
(dotimes (i +NUM_RECORDS+)
(let ((trade-ref (aref trades i)))
(progn (setf (lisp-memory-trade-trade-id trade-ref) i)
(setf (lisp-memory-trade-client-id trade-ref) 1)
(setf (lisp-memory-trade-venue-code trade-ref) 123)
(setf (lisp-memory-trade-instrument-code trade-ref) 321)
(setf (lisp-memory-trade-price trade-ref) i)
(setf (lisp-memory-trade-quantity trade-ref) i)
(if (oddp i)
(setf (lisp-memory-trade-side trade-ref) #\S)
(setf (lisp-memory-trade-side trade-ref) #\B))))))
(defun perf-run (run-num)
(let (
(start-t (get-internal-run-time))
(buy-cost 0)
(sell-cost 0))
(declare (type fixnum buy-cost))
(declare (type fixnum sell-cost))
(progn
(init-trades)
(dotimes (i +NUM_RECORDS+)
(let ((trade-ref (aref trades i)))
(if (equal (lisp-memory-trade-side trade-ref) #\B)
(incf buy-cost (the fixnum (* (lisp-memory-trade-price trade-ref) (lisp-memory-trade-quantity trade-ref))))
(incf sell-cost (the fixnum (* (lisp-memory-trade-price trade-ref) (lisp-memory-trade-quantity trade-ref)))))))
(format t "~d duration ~d ms~%" run-num (- (get-internal-run-time) start-t) )
(format t "buycost = ~d sellCost = ~d~%" buy-cost sell-cost))))
(defun run ()
(prep-trades)
(time(loop for i from 0 to 5 do (perf-run i))))