From: Andreas Rottmann <a.rottmann@gmx.at>
To: ludo@gnu.org (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: [PATCH] Take some lowhanging fruit to speed up R6RS fixnum operations
Date: Fri, 25 Mar 2011 13:16:21 +0100 [thread overview]
Message-ID: <8739mb1jl6.fsf@gmx.at> (raw)
In-Reply-To: <87zkokrsp7.fsf@vir.lan> (Andreas Rottmann's message of "Fri, 25 Mar 2011 00:42:44 +0100")
Andreas Rottmann <a.rottmann@gmx.at> writes:
> ludo@gnu.org (Ludovic Courtès) writes:
>
>> Hi Andreas,
>>
>> I’m all for your suggestion.
>>
>> Andreas Rottmann <a.rottmann@gmx.at> writes:
>>
>>> + (define-syntax define-fxop*
>>> + (syntax-rules ()
>>> + ((_ name op)
>>> + (define name
>>> + (case-lambda
>>> + ((x y)
>>> + (assert-fixnum x y)
>>> + (op x y))
>>> + (args
>>> + (assert-fixnums args)
>>> + (apply op args)))))))
>>> +
>>> + (define-fxop* fx=? =)
>>
>> How about making something like this (untested):
>>
>> (define-syntax define-fxop*
>> (syntax-rules ()
>> ((_ name op)
>> (define-syntax name
>> (lambda (s)
>> (syntax-case s ()
>> ((_ x y)
>> #'(begin
>> (assert-fixnum x y)
>> (op x y)))
>> ((_ args ...)
>> #'(apply op args))
>> (_ #'op)))))))
>>
>> This way, there’d be no procedure call involved and ‘=’, ‘+’, etc. would
>> use the corresponding instruction in the base case.
>>
> That's an excellent idea, and would probably boost performance quite a
> bit.
>
Sorry to reply to myself, but new evidence has been produced :-).
Using the following macro:
(define-syntax define-fxop*
(lambda (stx)
(define prefix (string->symbol "% "))
(define (make-procedure-name name)
(datum->syntax name
(symbol-append prefix (syntax->datum name)
'-procedure)))
(syntax-case stx ()
((_ name op)
(with-syntax ((proc-name (make-procedure-name #'name)))
#'(begin
(define (proc-name . args)
(assert-fixnums args)
(apply op args))
(define-syntax name
(lambda (stx)
(syntax-case stx ()
((_ x-expr y-expr)
#'(let ((x x-expr)
(y y-expr))
(assert-fixnum x y)
(op x y)))
((_ . args)
#'(proc-name . args))
(_
(identifier? stx)
#'proc-name))))))))))
It turns out that this does not have a great effect on the efficiency;
here are the numbers:
* stable-2.0 + rotty/wip-fixnum-speed (simple define-fxop*, clever fixnum?)
#+begin_example
% _build/meta/guile -e main -s benchmark-suite/guile-benchmark --benchmark-suite benchmarks r6rs-arithmetic.bm
;; running guile version 2.0.0.133-e47c9-dirty
;; calibrating the benchmarking framework...
;; framework time per iteration: 1.1444091796875e-7
("r6rs-arithmetic.bm: fixnum: fixnum? [yes]" 10000000 user 3.42 benchmark 2.2755908203125 bench/interp 2.2755908203125 gc 0.0)
("r6rs-arithmetic.bm: fixnum: fixnum? [no]" 10000000 user 3.42 benchmark 2.2755908203125 bench/interp 2.2755908203125 gc 0.0)
("r6rs-arithmetic.bm: fixnum: fxxor [2]" 10000000 user 6.96 benchmark 5.8155908203125 bench/interp 5.8155908203125 gc 0.0)
scheme@(guile-user)> ,time (run-benchmark)
clock utime stime cutime cstime gctime
23.81 23.76 0.00 0.00 0.00 0.00
#+end_example
* stable-2.0 + rotty/wip-fixnum-speed (macro-based define-fxop*, clever fixnum?)
#+begin_example
% _build/meta/guile -e main -s benchmark-suite/guile-benchmark --benchmark-suite benchmarks r6rs-arithmetic.bm
;; running guile version 2.0.0.133-e47c9-dirty
;; calibrating the benchmarking framework...
;; framework time per iteration: 1.52587890625e-7
("r6rs-arithmetic.bm: fixnum: fixnum? [yes]" 10000000 user 3.4 benchmark 1.87412109375 bench/interp 1.87412109375 gc 0.0)
("r6rs-arithmetic.bm: fixnum: fixnum? [no]" 10000000 user 3.42 benchmark 1.89412109375 bench/interp 1.89412109375 gc 0.0)
("r6rs-arithmetic.bm: fixnum: fxxor [2]" 10000000 user 6.72 benchmark 5.19412109375 bench/interp 5.19412109375 gc 0.0)
scheme@(guile-user)> ,time (run-benchmark)
clock utime stime cutime cstime gctime
22.76 22.73 0.00 0.00 0.00 0.00
#+end_example
So, that's around 5% improvment (on the ZIP benchmark) for an IMHO
significantly more hackish implementation. I'm not sure that's worth
it. WDYT?
Regards, Rotty
--
Andreas Rottmann -- <http://rotty.yi.org/>
next prev parent reply other threads:[~2011-03-25 12:16 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-22 23:20 Take some lowhanging fruit to speed up R6RS fixnum operations Andreas Rottmann
2011-03-22 23:20 ` [PATCH] " Andreas Rottmann
2011-03-24 21:51 ` Ludovic Courtès
2011-03-24 23:42 ` Andreas Rottmann
2011-03-25 12:16 ` Andreas Rottmann [this message]
2011-03-27 15:19 ` Ludovic Courtès
2011-03-27 22:20 ` Andreas Rottmann
2011-03-29 11:05 ` Andy Wingo
2011-03-30 1:37 ` Andreas Rottmann
2011-03-30 10:31 ` Andreas Rottmann
2011-03-30 10:58 ` Andreas Rottmann
2011-04-02 17:42 ` R6RS fixnum arithmetic optimizations Andreas Rottmann
2011-04-02 17:42 ` [PATCH 1/3] Add a few benchmarks for R6RS fixnum arithmetic Andreas Rottmann
2011-04-02 17:42 ` [PATCH 2/3] Several optimizations " Andreas Rottmann
2011-04-02 17:42 ` [PATCH 3/3] Add `fixnum?' VM primitive Andreas Rottmann
2011-04-04 21:53 ` Andy Wingo
2011-04-05 0:14 ` Andreas Rottmann
2011-04-06 12:42 ` define-inlinable Ludovic Courtès
2011-04-06 21:30 ` define-inlinable Andreas Rottmann
2011-04-06 22:24 ` define-inlinable Ludovic Courtès
2011-04-11 16:56 ` define-inlinable Andy Wingo
2011-04-11 20:01 ` define-inlinable Ludovic Courtès
2011-04-11 21:05 ` define-inlinable Andy Wingo
2011-04-11 22:11 ` define-inlinable Andreas Rottmann
2011-04-07 15:57 ` [PATCH 3/3] Add `fixnum?' VM primitive Ludovic Courtès
2011-04-04 21:28 ` Take some lowhanging fruit to speed up R6RS fixnum operations Andy Wingo
2011-04-04 22:00 ` Andreas Rottmann
2011-04-04 22:12 ` Andy Wingo
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=8739mb1jl6.fsf@gmx.at \
--to=a.rottmann@gmx.at \
--cc=guile-devel@gnu.org \
--cc=ludo@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).