M:SEQ Too Slow
"Michael A. Koerber" <[email protected]> Fri, 21 Jun 2002 09:58:14 -0400
| Newsgroups | gmane.lisp.matlisp.devel |
|---|---|
| Message-ID | <[email protected]> |
------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <[email protected]> I noted the following yesterday... * (time (setf tmp (m:seq 0 32767) done 'done)) Evaluation took: 45.28 seconds of real time 44.78 seconds of user run time 0.01 seconds of system run time 2 page faults and 785416 bytes consed. DONE Looking at SEQ.LISP I'd blame %PUSH-ON-END%. Due to time constraints I did a quick hack to use an ARRAY and coerce it to a LIST on return. I DON'T KNOW IF THIS IS A GOOD FIX (the fastest and compatible with other MATLISP internal uses or not), but it answered the mail for me yesterday. This is the new timing... * (time (setf tmp (seq 0 32767) done 'done)) Evaluation took: 0.02 seconds of real time 0.02 seconds of user run time 0.0 seconds of system run time 0 page faults and 393224 bytes consed. DONE * FWIW the diffs and the new SEQ.LIST are attached. Note also that I moved the check for STEP equal to zero earlier in the routine. ------- =_aaaaaaaaaa0 Content-Type: text/plain; name="tmp.txt"; charset="us-ascii" Content-ID: <[email protected]> Content-Description: Diff's for SEQ.LISP --- /home/mak/src/matlisp/src/seq.lisp Tue Jul 11 14:02:03 2000 +++ seq.lisp Thu Jun 20 11:14:09 2002 @@ -85,16 +85,21 @@ (setq end step) (setq step 1))) - (let ((start (rationalize start)) - (type (type-of step)) - (step (rationalize step)) - (end (rationalize end)) - (seq nil)) + (if (zerop step) + (error "STEP equal to 0")) + + (let* ((start (rationalize start)) + (type (type-of step)) + (step (rationalize step)) + (end (rationalize end)) + (size (1+ (/ (- end start) step))) + (seq (make-array size :element-type type))) - (if (zerop step) - (error "STEP equal to 0")) - (do ((x start (+ x step))) + (do ((x start (+ x step)) + (n 0 (incf n))) + ((if (> step 0) (> x end) - (< x end)) seq) - (%push-on-end% (coerce x type) seq)))) + (< x end)) (coerce seq 'list)) + + (setf (aref seq n) (coerce x type))))) ------- =_aaaaaaaaaa0 Content-Type: text/plain; name="seq.lisp"; charset="us-ascii" Content-ID: <[email protected]> Content-Description: New SEQ.LISP file ;;; -*- Mode: lisp; Syntax: ansi-common-lisp; Package: :matlisp; Base: 10 -*- ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Copyright (c) 2000 The Regents of the University of California. ;;; All rights reserved. ;;; ;;; Permission is hereby granted, without written agreement and without ;;; license or royalty fees, to use, copy, modify, and distribute this ;;; software and its documentation for any purpose, provided that the ;;; above copyright notice and the following two paragraphs appear in all ;;; copies of this software. ;;; ;;; IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY ;;; FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ;;; ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF ;;; THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF ;;; SUCH DAMAGE. ;;; ;;; THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, ;;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ;;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE ;;; PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF ;;; CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ;;; ENHANCEMENTS, OR MODIFICATIONS. ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Originally written by Tunc Simsek, Univ. of California, Berkeley, ;;; 2000, [email protected] ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; $Id: seq.lisp,v 1.3 2000/07/11 18:02:03 simsek Exp $ ;;; ;;; $Log: seq.lisp,v $ ;;; Revision 1.3 2000/07/11 18:02:03 simsek ;;; o Added credits ;;; ;;; Revision 1.2 2000/07/11 02:11:56 simsek ;;; o Added support for Allegro CL ;;; ;;; Revision 1.1 2000/04/14 00:12:48 simsek ;;; Initial revision. ;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (in-package "MATLISP") #+nil (export '(seq)) (if (not (fboundp '%push-on-end%)) (defmacro %push-on-end% (value location) `(setf ,location (nconc ,location (list ,value))))) (defun seq (start step &optional end) " Syntax ====== (SEQ start [step] end) Purpose ======= Creates a list containing the sequence START, START+STEP, ..., START+(N-1)*STEP where | END-START | N = | --------- | + 1 | STEP | -- -- The representations of START,STEP,END are assumed to be exact (i.e. the arguments are rationalized. The type of the elements in the sequence are of the same type as STEP. The optional argument STEP defaults to 1. " (if (not end) (progn (setq end step) (setq step 1))) (if (zerop step) (error "STEP equal to 0")) (let* ((start (rationalize start)) (type (type-of step)) (step (rationalize step)) (end (rationalize end)) (size (1+ (/ (- end start) step))) (seq (make-array size :element-type type))) (do ((x start (+ x step)) (n 0 (incf n))) ((if (> step 0) (> x end) (< x end)) (coerce seq 'list)) (setf (aref seq n) (coerce x type))))) ------- =_aaaaaaaaaa0--