From: malc <malc@pulsesoft.com>
To: Christophe TROESTLER <debian00@tiscalinet.be>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Re: float boxing (was: matrix-matrix multiply)
Date: Thu, 24 Oct 2002 04:00:41 +0400 (MSD) [thread overview]
Message-ID: <Pine.LNX.4.44.0210240348380.2152-100000@home.oyster.ru> (raw)
In-Reply-To: <Pine.LNX.4.44.0210231605530.824-100000@home.oyster.ru>
On Wed, 23 Oct 2002, malc wrote:
> > A few questions in view of this. First, on my machine (AMD Athlon
> > 1GHz running GNU/Linux), the timings give a preference to ref.ml
> >
> > time ./ref 100000000
> > real 0m1.279s user 0m1.280s sys 0m0.000s
> > time ./ref2 100000000
> > real 0m1.411s user 0m1.380s sys 0m0.000s
> >
> > What could be a reason for that?
>
> I think the reason is simple, both are more or less nop operations,
> x or x.f is not used anywhere, hence no need to allocate the float.
> This short example highlights the difference:
>
> let useref n =
> let x = ref 1.0 in
> for i = 1 to n do x := !x +. 1.0 done;
> !x
>
> type t = { mutable f:float };;
> let userec n =
> let x = { f = 1.0 } in
> for i = 1 to n do x.f <- x.f +. 1.0 done;
> x.f
>
> let _ =
> let n = int_of_string Sys.argv.(2) in
> Printf.printf "%f\n"
> (if Sys.argv.(1) = "ref" then
> useref n
> else
> userec n)
>
> ref# time ./refrec rec 100000000
> 100000001.000000
>
> real 0m2.283s
> user 0m2.280s
> sys 0m0.000s
> ref# time ./refrec ref 100000000
> 100000001.000000
>
> real 0m1.916s
> user 0m1.910s
> sys 0m0.010s
>
> More or less same machine here.
I believe i should add something here. Let's look at the inner loops.
Mutable version:
.L107:
fld1
faddl (%ecx)
fstpl (%ecx)
addl $2, %eax
cmpl %ebx, %eax
jle .L107
Suboptimal but ok...
Reference version:
.L101:
.L103: movl young_ptr, %eax
subl $12, %eax
movl %eax, young_ptr
cmpl young_limit, %eax
jb .L104
leal 4(%eax), %ecx
movl $2301, -4(%ecx)
fld1
faddl (%esi)
fstpl (%ecx)
movl %ecx, %esi
addl $2, %ebx
cmpl %edx, %ebx
jle .L101
Lots of instructions + boxing.. And yet its faster than mutable one..
Wonders of modern CPUs.
My first take at simplest asm code doing the same:
mov eax, n
fld1
fld1
LL:
fadd st, st(1)
dec eax
jnz LL
fstp result
fstp st
ref# time ./c 100000000
100000001.000000
real 0m0.394s
user 0m0.390s
sys 0m0.000s
(Turned out that both gcc and icc produce similar code give or take)
P.S. It would be interesting to see timings produced by P3/P4.
--
mailto:malc@pulsesoft.com
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2002-10-24 0:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-18 20:09 [Caml-list] matrix-matrix multiply - O'Caml is 6 times slower than C Paul Stodghill
2002-10-20 9:42 ` Xavier Leroy
2002-10-20 18:06 ` Paul Stodghill
2002-10-20 21:58 ` Issac Trotts
2002-10-23 10:16 ` [Caml-list] Re: float boxing (was: matrix-matrix multiply) Christophe TROESTLER
2002-10-23 12:08 ` malc
2002-10-24 0:00 ` malc [this message]
2002-10-21 12:53 ` [Caml-list] matrix-matrix multiply - O'Caml is 6 times slower than C Xavier Leroy
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=Pine.LNX.4.44.0210240348380.2152-100000@home.oyster.ru \
--to=malc@pulsesoft.com \
--cc=caml-list@inria.fr \
--cc=debian00@tiscalinet.be \
/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