6be7bf9a9558b03db6aa2141726ffd1a2e3353d4
[uffi.git] / benchmarks / allocation.cl
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          allocation.cl
6 ;;;; Purpose:       Benchmark allocation and slot-access speed
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Mar 2002
9 ;;;;
10 ;;;; $Id: allocation.cl,v 1.2 2002/03/21 14:49:14 kevin Exp $
11 ;;;;
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; UFFI users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
18
19 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
20 (in-package :cl-user)
21
22
23 (defun stk-int ()
24   #+allegro
25   (ff:with-stack-fobject (ptr :int) 
26     (setf (ff:fslot-value ptr) 0))
27   #+lispworks
28   (fli:with-dynamic-foreign-objects ((ptr :int))
29     (setf (fli:dereference ptr) 0))
30   #+cmu
31   (alien:with-alien ((ptr alien:signed))
32     (setf ptr 0))
33   )
34
35 (defun stk-vector ()
36   #+allegro
37   (ff:with-stack-fobject (ptr '(:array :int 10) )
38     (setf (ff:fslot-value ptr 5) 0))
39   #+lispworks
40   (fli:with-dynamic-foreign-objects ((ptr (:c-array :int 10)))
41     (setf (fli:dereference ptr 5) 0))
42   #+cmu
43   (alien:with-alien ((ptr (alien:array alien:signed 10)))
44     (setf (alien:deref ptr 5) 0))
45   )
46
47 (defun stat-int ()
48   #+allegro
49   (let ((ptr (ff:allocate-fobject :int :c)))
50     (declare (dynamic-extent ptr))
51     (setf (ff:fslot-value-typed :int :c ptr) 0)
52     (ff:free-fobject ptr))
53   #+lispworks
54   (let ((ptr (fli:allocate-foreign-object :type :int)))
55     (declare (dynamic-extent ptr))
56     (setf (fli:dereference ptr) 0)
57     (fli:free-foreign-object ptr))
58   #+cmu
59   (let ((ptr (alien:make-alien (alien:signed 32))))
60     (declare ;;(type (alien (* (alien:unsigned 32))) ptr)
61              (dynamic-extent ptr))
62     (setf (alien:deref ptr) 0)
63     (alien:free-alien ptr))
64   )
65
66 (defun stat-vector ()
67   #+allegro
68   (let ((ptr (ff:allocate-fobject '(:array :int 10) :c)))
69     (declare (dynamic-extent ptr))
70     (setf (ff:fslot-value-typed '(:array :int 10) :c ptr 5) 0)
71     (ff:free-fobject ptr))
72   #+lispworks
73   (let ((ptr (fli:allocate-foreign-object :type '(:c-array :int 10))))
74     (declare (dynamic-extent ptr))
75     (setf (fli:dereference ptr 5) 0)
76     (fli:free-foreign-object ptr))
77   #+cmu
78   (let ((ptr (alien:make-alien (alien:array (alien:signed 32) 10))))
79     (declare ;;(type (alien (* (alien:unsigned 32))) ptr)
80              (dynamic-extent ptr))
81     (setf (alien:deref ptr 5) 0)
82     (alien:free-alien ptr))
83   )
84
85
86 (defun stk-vs-stat ()
87   (format t "~&Stack allocation, Integer")
88   (time (dotimes (i 1000) 
89           (dotimes (j 1000)
90             (stk-int))))
91   (format t "~&Static allocation, Integer")
92   (time (dotimes (i 1000) 
93           (dotimes (j 1000)
94             (stat-int))))
95   (format t "~&Stack allocation, Vector")
96   (time (dotimes (i 1000) 
97           (dotimes (j 1000)
98             (stk-int))))
99   (format t "~&Static allocation, Vector")
100   (time (dotimes (i 1000) 
101           (dotimes (j 1000)
102             (stat-int))))
103 )
104
105
106                             
107