1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: allocation.cl
6 ;;;; Purpose: Benchmark allocation and slot-access speed
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Mar 2002
10 ;;;; $Id: allocation.cl,v 1.2 2002/03/21 14:49:14 kevin Exp $
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
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 ;;;; *************************************************************************
19 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
25 (ff:with-stack-fobject (ptr :int)
26 (setf (ff:fslot-value ptr) 0))
28 (fli:with-dynamic-foreign-objects ((ptr :int))
29 (setf (fli:dereference ptr) 0))
31 (alien:with-alien ((ptr alien:signed))
37 (ff:with-stack-fobject (ptr '(:array :int 10) )
38 (setf (ff:fslot-value ptr 5) 0))
40 (fli:with-dynamic-foreign-objects ((ptr (:c-array :int 10)))
41 (setf (fli:dereference ptr 5) 0))
43 (alien:with-alien ((ptr (alien:array alien:signed 10)))
44 (setf (alien:deref ptr 5) 0))
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))
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))
59 (let ((ptr (alien:make-alien (alien:signed 32))))
60 (declare ;;(type (alien (* (alien:unsigned 32))) ptr)
62 (setf (alien:deref ptr) 0)
63 (alien:free-alien ptr))
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))
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))
78 (let ((ptr (alien:make-alien (alien:array (alien:signed 32) 10))))
79 (declare ;;(type (alien (* (alien:unsigned 32))) ptr)
81 (setf (alien:deref ptr 5) 0)
82 (alien:free-alien ptr))
87 (format t "~&Stack allocation, Integer")
88 (time (dotimes (i 1000)
91 (format t "~&Static allocation, Integer")
92 (time (dotimes (i 1000)
95 (format t "~&Stack allocation, Vector")
96 (time (dotimes (i 1000)
99 (format t "~&Static allocation, Vector")
100 (time (dotimes (i 1000)