Wasting Time
From: David Steuber (david_at_david-steuber.com)
Date: 05/28/04
- Next message: mikel: "Re: Haskell: functional languages vs Lisp"
- Previous message: Kaz Kylheku: "Haskell: functional languages vs Lisp"
- Next in thread: Gareth McCaughan: "Re: Wasting Time"
- Reply: Gareth McCaughan: "Re: Wasting Time"
- Reply: André Thieme: "making Lisp faster by giving it 40 more bits (was: Wasting Time)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 28 May 2004 16:55:57 -0400
I wrote a simple little function to simulate a web page request taking
several seconds to calculate before beginning to return a result. As
strange as it may sound, I got side tracked because I was disappointed
in the efficiency of my time wasting function. I actually learned a
few things along the way.
;;; Time waster
;; the declarations in this function make no noticable difference
(defun waste-time ()
(do ((tim (+ 2 (get-universal-time)))
(i 0 (the fixnum (1+ i))))
((< tim (get-universal-time)) i)
(declare (fixnum i))))
;; the declerations in this function improved speed by about x10
(defun count-to-n (n)
(do ((i 0 (the fixnum (1+ i))))
((<= n i) i)
(declare (fixnum i n))))
;; self explanatory
(defun time-waste-time ()
(let ((tim (time (waste-time))))
(time (count-to-n tim))))
(time-waste-time)
(let ((res nil))
(dotimes (i 10 res)
(push (time-waste-time) res)))
;; this shows that (get-universal-time) is NOT where the time is spent
(time (dotimes (i 10000000) (get-universal-time)))
;; shis shows lots of work being done just by bignum assignment
(time (let ((tim))
(dotimes (i 10000000 tim)
(setf tim (get-universal-time)))))
;; this shows bignum compares being fairly fast
(time (let ((tim (+ 2 (get-universal-time))))
(dotimes (i 10000000 tim)
(< tim (get-universal-time)))))
My expectation was for larger values from waste-time. I can't tell
from the above what is making waste-time so 'slow'. I expect the do
to loop much faster than it does. waste-time also conses a lot. It
is comparable to bignum assignment rather than to the bignum compare.
If waste-time was doing useful work to return a dynamicly generated
file in a single threaded HTTP server, how would it be made to work
concurrently with other requests that require the same sort of
processing? It seems to me that some sort of yield function would
have to be thrown in. This is why I operate under the belief that a
thread per request is the better model. I'm not sure how you set up a
Lisp process to run with smaller stacks for threads. On my Mac, I
have 'ulimit -s 8192' in my .profile for SBCL. Stacks may not need to
be larger than that depending on the app.
-- An ideal world is left as an excercise to the reader. --- Paul Graham, On Lisp 8.1
- Next message: mikel: "Re: Haskell: functional languages vs Lisp"
- Previous message: Kaz Kylheku: "Haskell: functional languages vs Lisp"
- Next in thread: Gareth McCaughan: "Re: Wasting Time"
- Reply: Gareth McCaughan: "Re: Wasting Time"
- Reply: André Thieme: "making Lisp faster by giving it 40 more bits (was: Wasting Time)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]