caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jon Harrop <jon@jdh30.plus.com>
To: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Gripes with array
Date: Sun, 12 Sep 2004 16:33:38 +0100	[thread overview]
Message-ID: <200409121633.38389.jon@jdh30.plus.com> (raw)
In-Reply-To: <AA0A2056-0434-11D9-ADA6-00039310CAE8@inria.fr>

On Saturday 11 September 2004 21:53, Damien Doligez wrote:
> ... Frankly,
> I find it hard to imagine that it would give a noticeable run-time
> improvement on any program.  Most likely, it would make them all a
> fraction
> of a percent slower, except for the most synthetic of benchmarks.

If it let you do extensible arrays safely then it could be used to reduce the 
asymptotic complexity of array append- or prepend-element from O(n) to 
amortized O(1) and "i"th insert from O(n) to amortized O(min{i, n-i}).

> > No, I don't think the performance improvement would justify your time
> > or the
> > loss of safety.
>
> No loss of safety if we don't export that primitive and use it only in
> Array.init.  After all, it only breaks type safety, and only if you use
> it wrong.

I was assuming that you would export it. My discrete wavelet transform (DWT) 
code, for example, is easily proven to fill all array elements but it fills 
them out of order (I've considered ways to make it fill in-order but they all 
incur significant performance penalties elsewhere, e.g. lots of swapping). So 
I was thinking of using unsafe_make for that. Still, I don't think it would 
be worth your writing it.

Having said that, it might be possible to abstract the array lookup and 
replace it with a clever function to work out where the "i"th element really 
is. Then you could give Array.init a continuation. Hmm...

> >  Could you add a memset to String.create though? :-)
>
> String.make

I meant for safety reasons - either don't export String.create or make it 
safe, e.g. "let create n = make n '\000'".

> > An array_init2 function which specialises the array type but uses an
> > external
> > "f" function betters the time taken by Array.init by ~36% (perhaps not
> > significantly different):
>
> That's from getting rid of the float/non-float test.  Nothing to do with
> the cost of initializing twice.

Yes. Optimising that would be much more productive. Am I right in thinking 
that ocamlopt doesn't hoist the test out of the loop?

Such optimisations would be best done at run-time, e.g. by Basile's JIT. Where 
is he? ;-)

Cheers,
Jon.

-------------------
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


  reply	other threads:[~2004-09-12 15:37 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-09  2:10 Jon Harrop
2004-09-09  5:08 ` Ville-Pertti Keinonen
2004-09-09  7:17 ` Jean-Christophe Filliatre
2004-09-09  8:23   ` Richard Jones
2004-09-09  9:08     ` Olivier Andrieu
2004-09-09 12:08       ` Basile Starynkevitch [local]
2004-09-09 12:31         ` Damien Doligez
2004-09-09 10:42     ` Gerd Stolpmann
2004-09-09  9:37 ` Damien Doligez
2004-09-09 10:34   ` Jean-Christophe Filliatre
2004-09-09 12:15     ` Igor Pechtchanski
2004-09-09 13:01   ` Brian Hurt
2004-09-09 20:08     ` [Caml-list] 32-bit is sticking around Brandon J. Van Every
2004-09-09 21:04       ` Jon Harrop
2004-09-11 15:30         ` Lars Nilsson
2004-09-11 16:24           ` [off topic] " David MENTRE
2004-09-11 17:52             ` Lars Nilsson
     [not found]           ` <200409111656.11952.jon@jdh30.plus.com>
2004-09-11 17:47             ` Lars Nilsson
2004-09-09 16:58   ` [Caml-list] Gripes with array Jon Harrop
2004-09-10  5:56     ` Array.init (was [Caml-list] Gripes with array) Christophe Raffalli
2004-09-10  8:53       ` Richard Jones
2004-09-10 14:50         ` Damien Doligez
2004-09-13  7:02       ` Christophe Raffalli
2004-09-10 13:45     ` [Caml-list] Gripes with array Damien Doligez
2004-09-11  1:43       ` skaller
2004-09-11  3:16         ` skaller
2004-09-11 14:36       ` Jon Harrop
2004-09-11 20:53         ` Damien Doligez
2004-09-12 15:33           ` Jon Harrop [this message]
2004-09-12 16:07             ` Basile Starynkevitch [local]
2004-09-10 23:48 ` brogoff

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=200409121633.38389.jon@jdh30.plus.com \
    --to=jon@jdh30.plus.com \
    --cc=caml-list@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).