From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.devel Subject: what's a cons worth? Date: Thu, 14 Oct 2010 20:24:05 +0200 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1287080464 10468 80.91.229.12 (14 Oct 2010 18:21:04 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 14 Oct 2010 18:21:04 +0000 (UTC) To: guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Oct 14 20:21:03 2010 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1P6SQ6-0001Ps-FM for guile-devel@m.gmane.org; Thu, 14 Oct 2010 20:21:03 +0200 Original-Received: from localhost ([127.0.0.1]:33305 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P6SPy-0007p1-Ao for guile-devel@m.gmane.org; Thu, 14 Oct 2010 14:20:42 -0400 Original-Received: from [140.186.70.92] (port=59799 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P6SPq-0007oM-Lh for guile-devel@gnu.org; Thu, 14 Oct 2010 14:20:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P6SPp-0004LR-AQ for guile-devel@gnu.org; Thu, 14 Oct 2010 14:20:34 -0400 Original-Received: from a-pb-sasl-quonix.pobox.com ([208.72.237.25]:42039 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P6SPp-0004LN-7Q for guile-devel@gnu.org; Thu, 14 Oct 2010 14:20:33 -0400 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 91271DE413 for ; Thu, 14 Oct 2010 14:20:32 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:mime-version:content-type; s=sasl; bh=4 86RsXmqxDf6M0mB3qgJY+vFNxs=; b=lI0hIxa2VnxRD9ix/Tlu8+x75Zto5nza0 S9lULmDLqDQj4CycMD8LdjCi1QvUgFo8SsUsm5yiq0eGSHLw3ulhXLSABibdnPfb i9FAUpk5W6j5qbOd0votmWmBHLdYJUhSS1qcSFkt5ma5ogiElq5ILrA1TbSIFd3z VVxC1/6ujQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:mime-version:content-type; q=dns; s=sasl; b=YQm CyqBimXBDgBMkJwjsulc/foy2/qy+AlnhixBDG0Mp+z5BvC4tYnjBBaqiXloGJso D84EuDvFgqNMqoEG7QKZa7j0UgEu0Gt4ioOMxojfa1auMgi6AIdBHyOIHVHOet4q DT/zeVWJWggX25TbT6v6fuLDHaLIAQE1zFRPQVVg= Original-Received: from a-pb-sasl-quonix. (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 8D3D8DE412 for ; Thu, 14 Oct 2010 14:20:32 -0400 (EDT) Original-Received: from unquote.localdomain (unknown [79.156.147.212]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTPSA id 1215DDE411 for ; Thu, 14 Oct 2010 14:20:31 -0400 (EDT) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-Pobox-Relay-ID: BB4CAB88-D7BF-11DF-B464-030CEE7EF46B-02397024!a-pb-sasl-quonix.pobox.com X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:11043 Archived-At: Hello all, I was wondering what the cost of a cons was, and decided to do an experiment: scheme@(guile-user)> (define (count-loop n) (let lp ((n n)) (if (> n 0) (lp (1- n))))) scheme@(guile-user)> ,time (count-loop 1000000000) clock utime stime cutime cstime gctime 46.02 45.92 0.00 0.00 0.00 0.00 scheme@(guile-user)> (/ 46.02 1000000000) $1 = 4.602e-8 scheme@(guile-user)> (define (cons-loop n) (let lp ((n n)) (cons n n) (if (> n 0) (lp (1- n))))) scheme@(guile-user)> ,time (cons-loop 1000000000) clock utime stime cutime cstime gctime 109.09 108.43 0.45 0.00 0.00 0.00 scheme@(guile-user)> (- (/ 109.09 1000000000) $1) $2 = 6.307e-8 Now, cons-loop should have optimized out that cons, but it didn't; oh well. The better for my testing. I ran a loop counting down from an (American) billion. Then I ran a loop doing the same, but consing a pair before looping. Memory stayed fairly constant, FWIW. So if I understand this correctly, on my machine, a 2.2 GHz 64-bit intel laptop, a cons takes 63 nanoseconds (amortized), or about 140 cycles (amortized). Then again there is the cost of the local variable refs, which count-loop doesn't have, but that makes this the upper bound for cons cost on this machine. For what it's worth, Andy -- http://wingolog.org/