From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: gava@univ-paris12.fr
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Multiplication of matrix in C and OCaml
Date: Thu, 08 Feb 2007 11:14:01 +0900 (JST) [thread overview]
Message-ID: <20070208.111401.55511744.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <45CA63F5.6020301@univ-paris12.fr>
From: Frédéric Gava <gava@univ-paris12.fr>
> I compared multiplication of matrix in C and OCaml and I was a little
> surprise to see that the following C code (using -O2) is 8 time faster
> than the OCaml one (even with -unsafe).
>
> Anybody have an idea to optimize my OCaml code or know why is there this
> "big" difference ?
>
> ps: the difference is the same even when I use a non-polymorphic
> multiplication
This is not what I see:
Multiplying 1000 times two 50x50 matrices on a Pentium M 1.8G, using
your code.
ocamlopt -unsafe polymorphic: 5.4s
ocamlopt -unsafe -inline 100 polymorphic: 5.0s
ocamlopt -unsafe monomorphic: 4.4s
gcc polymorphic: 6.5s
gcc monomorphic: 5.8s
gcc -O3 monomorphic: 4.7s
So, actually it seems that ocamlopt is even faster than gcc in many
cases.
Now, I also found a strange result:
gcc -O3 monomorphic: 1.4s
So I looked at the generated assembler:
.globl add
.type add, @function
add:
pushl %ebp
movl %esp, %ebp
subl $56, %esp
leal -56(%ebp), %eax
leave
ret
.size add, .-add
.p2align 2,,3
.globl mult
.type mult, @function
mult:
pushl %ebp
movl %esp, %ebp
subl $56, %esp
leal -56(%ebp), %eax
leave
ret
It seems that returning a local value is not well-defined, and gcc
just decides that this value being unused inside the function, there
is no need to do any computation!
---------------------------------------------------------------------------
Jacques Garrigue Nagoya University garrigue at math.nagoya-u.ac.jp
<A HREF=http://www.math.nagoya-u.ac.jp/~garrigue/>JG</A>
next prev parent reply other threads:[~2007-02-08 2:14 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-07 23:42 Frédéric Gava
2007-02-08 2:14 ` Jacques Garrigue [this message]
2007-02-08 9:27 ` [Caml-list] " Frédéric Gava
2007-02-08 9:38 ` Frédéric Gava
2007-02-08 12:08 ` Jacques Garrigue
2007-02-08 9:56 ` Frédéric Gava
2007-02-08 10:45 ` Xavier Leroy
2007-02-08 15:16 ` Frédéric Gava
2007-02-09 2:58 ` Jacques Garrigue
2007-02-09 9:06 ` ls-ocaml-developer-2006
2007-02-09 10:32 ` ls-ocaml-developer-2006
2007-02-09 14:22 ` skaller
2007-02-09 21:47 ` ls-ocaml-developer-2006
2007-02-09 21:55 ` Andrej Bauer
2007-02-09 22:36 ` ls-ocaml-developer-2006
2007-02-09 23:53 ` Jon Harrop
2007-02-10 1:41 ` ls-ocaml-developer-2006
2007-02-10 2:24 ` Jon Harrop
2007-02-10 14:41 ` ls-ocaml-developer-2006
2007-02-10 14:52 ` Jon Harrop
2007-02-10 15:51 ` ls-ocaml-developer-2006
2007-02-10 16:10 ` Xavier Leroy
2007-02-10 16:11 ` Jon Harrop
2007-02-10 14:55 ` Mattias Engdegård
2007-02-11 13:13 ` Christophe Raffalli
2007-02-10 1:10 ` Brian Hurt
2007-02-10 1:16 ` Robert Roessler
2007-02-09 23:56 ` Jon Harrop
2007-02-09 12:05 ` Jon Harrop
2007-02-09 12:35 ` ls-ocaml-developer-2006
2007-02-09 13:50 ` Brian Hurt
2007-02-09 14:23 ` Gerd Stolpmann
2007-02-09 14:24 Frederic GAVA
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070208.111401.55511744.garrigue@math.nagoya-u.ac.jp \
--to=garrigue@math.nagoya-u.ac.jp \
--cc=caml-list@yquem.inria.fr \
--cc=gava@univ-paris12.fr \
/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