caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] OCaml image blending performance
Date: Wed, 6 Feb 2008 23:34:02 +0000	[thread overview]
Message-ID: <200802062334.02485.jon@ffconsultancy.com> (raw)
In-Reply-To: <854c25eb0802061229o34a6155dncca9d8492cfe6932@mail.gmail.com>

On Wednesday 06 February 2008 20:29:05 Ilmari Heikkinen wrote:
> The C and Caml versions don't produce the same results, but should
> have the same amount of computation (don't take my word for it though,
> I don't know why the results differ.)

You should post working code if you want people to optimize it. I suspect 
you've incorrectly assumed that OCaml has full-width ints in this case 
because it does work here on my 64-bit machine.

> ./build.sh
>
> cblend
>
> real	0m1.466s
> user	0m1.456s
> sys	0m0.008s
>
> blend
>
> real	0m5.463s
> user	0m5.456s
> sys	0m0.012s
>
> blend2
>
> real	0m3.423s
> user	0m3.404s
> sys	0m0.012s

On 2.2GHz AMD64, I get:

$ ./build.sh

cblend

real    0m6.337s
user    0m6.048s
sys     0m0.032s

blend

real    0m14.965s
user    0m14.281s
sys     0m0.096s

blend2

real    0m9.639s
user    0m9.333s
sys     0m0.056s

OCaml is not competitive here for two main reasons:

. Full-size integer arithmetic is not very fast in OCaml.
. Abstractions often cost performance in OCaml.

In this case, most of the speed loss can be regained by simply aggressively 
inlining everything, which is exactly what you (ab)used C macros for in the C 
code.

If you want to get more interesting then you can look at metaprogramming in 
OCaml, either by generating OCaml code, using MetaOCaml or JIT compiling 
using LLVM. You should be able to meet or beat C that way. At the very least, 
you can write OCaml programs to take the pain away from writing C programs by 
hand... :-)

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?e


  parent reply	other threads:[~2008-02-06 23:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-06 20:29 Ilmari Heikkinen
2008-02-06 22:12 ` [Caml-list] " Pal-Kristian Engstad
2008-02-06 23:30   ` Jon Harrop
2008-02-06 23:34 ` Jon Harrop [this message]
2008-02-07 11:01   ` Richard Jones
2008-02-07 11:13     ` Dominique Martinet
2008-02-07 12:29     ` Mauricio Fernandez
2008-02-07 15:04     ` Jon Harrop
     [not found] ` <854c25eb0802070607t4b2ed641xa3bc19e8384ce23@mail.gmail.com>
2008-02-07 14:10   ` Ilmari Heikkinen
2008-02-07 14:08     ` Jon Harrop

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=200802062334.02485.jon@ffconsultancy.com \
    --to=jon@ffconsultancy.com \
    --cc=caml-list@yquem.inria.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;
as well as URLs for NNTP newsgroup(s).