From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?B?VsOtdG9yIERlIEFyYcO6am8=?= Newsgroups: gmane.lisp.guile.user Subject: Re: Is this a good use for "compile" Date: Mon, 19 Feb 2018 21:08:25 -0300 Message-ID: <5d3802ce-88b8-7b8a-13e5-b1fbd9dfd0c9@sapo.pt> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1519085222 8048 195.159.176.226 (20 Feb 2018 00:07:02 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 20 Feb 2018 00:07:02 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 To: Mark Carter , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Feb 20 01:06:58 2018 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1envSS-0001iW-VT for guile-user@m.gmane.org; Tue, 20 Feb 2018 01:06:57 +0100 Original-Received: from localhost ([::1]:52874 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1envUV-00051i-8R for guile-user@m.gmane.org; Mon, 19 Feb 2018 19:09:03 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36089) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1envU6-00051P-Rx for guile-user@gnu.org; Mon, 19 Feb 2018 19:08:39 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1envU2-0001By-RJ for guile-user@gnu.org; Mon, 19 Feb 2018 19:08:38 -0500 Original-Received: from relay2.ptmail.sapo.pt ([212.55.154.22]:39552) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1envU2-00019Z-FN for guile-user@gnu.org; Mon, 19 Feb 2018 19:08:34 -0500 Original-Received: (qmail 22843 invoked from network); 20 Feb 2018 00:08:30 -0000 Original-Received: (qmail 3251 invoked from network); 20 Feb 2018 00:08:30 -0000 Original-Received: from unknown (HELO [192.168.0.15]) (vbuaraujo@sapo.pt@[201.37.162.121]) (envelope-sender ) by ptmail-mta-auth02 (qmail-ptmail-1.0.0) with ESMTPSA for ; 20 Feb 2018 00:08:30 -0000 X-PTMail-RemoteIP: 201.37.162.121 X-PTMail-AllowedSender-Action: X-PTMail-Service: default In-Reply-To: Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 212.55.154.22 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:14477 On 18/02/2018 18:56, Mark Carter wrote: > New scheme user here. > > Suppose I'm writing a spreadsheet. The user inputs a formula for a cell. > > The plan is to use guile's peg parser to convert the formula into a > lambda expression, which I then compile in order to speed-up subsequent > processing. > > So, suppose I convert the user's formula to a list, which turns out to > be, for example: '(lambda (x) (+ x 13)) and compile it and save it in a > formula table: > > (hash-set! my-cell-formulae some-cell-ref (compile '(lambda (x) (+ x 13)))) > > So I can I expect a speed-up by having done the compile, as opposed to > an eval? > > I assume the answer is "yes", but I wanted to check. We can try this out: scheme@(guile-user)> (use-modules (system base compile)) scheme@(guile-user)> (define exp '(lambda (n) (let loop ([i n] [total 0]) (if (= i 0) total (loop (1- i) (+ i total)))))) scheme@(guile-user)> (define f1 (eval exp (interaction-environment))) scheme@(guile-user)> (define f2 (compile exp #:env (interaction-environment))) scheme@(guile-user)> ,time (f1 1000000) $2 = 500000500000 ;; 0.845240s real time, 0.895351s run time. 0.071494s spent in GC. scheme@(guile-user)> ,time (f2 1000000) $3 = 500000500000 ;; 0.067317s real time, 0.067278s run time. 0.000000s spent in GC. So the answer does seem to be "yes": the compiled procedure is much faster. -- Vítor De Araújo https://elmord.org/