From: Mark Carter <alt.mcarter@gmail.com>
To: guile-user@gnu.org
Subject: Re: Is this a good use for "compile"
Date: Tue, 20 Feb 2018 09:28:07 +0000 [thread overview]
Message-ID: <1be8aa32-69f9-afec-321b-8b5b1d041c76@gmail.com> (raw)
In-Reply-To: <5d3802ce-88b8-7b8a-13e5-b1fbd9dfd0c9@sapo.pt>
On 20/02/18 00:08, Vítor De Araújo wrote:
>
> 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.
>
Thanks. A 10X speedup is just what the doctor ordered.
As it happened, I was looking for a way to time functions, and didn't
realise that guile has a convenient way of doing this.
next prev parent reply other threads:[~2018-02-20 9:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-18 21:56 Is this a good use for "compile" Mark Carter
2018-02-19 17:30 ` Matt Wette
2018-02-20 0:08 ` Vítor De Araújo
2018-02-20 9:28 ` Mark Carter [this message]
-- strict thread matches above, loose matches on Subject: below --
2018-02-20 11:03 Mark Carter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1be8aa32-69f9-afec-321b-8b5b1d041c76@gmail.com \
--to=alt.mcarter@gmail.com \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).