logo       
Google Custom Search
    AddThis Social Bookmark Button

Re: ExtArray?: msg#00034

Subject: Re: ExtArray?
Hi,

Did you do any benchmarks?  I did a quick, creating 10000 arrays of random size between 0-1000 (a couple preliminary tests of size 0-10000 elements gave a similar trend).  On average,  I get results like:

byte code:
jones 6.9 (from CVS)
hurt 7.2 (from email)
skaller  5.8 (list with remembered size - see below)

native code:
jones  0.82
hurt  0.80
skaller 0.72

So, it would seem that the version which uses lists + length as an intermediate representation is the fastest.  Caveat: I probably didn't run it long enough/with large enough arrays to test the effects of garbage collection. Brian's version might be better in these cases, but that may require more in-depth testing.  But Max's version is much simpler! :)

I think these results suggest that it may make a lot of sense to have find_all return a list.  (As Max suggested, perhaps a common function called by both find_all and filter, which returns list * length).

-Amit

(Code for skaller below)

let filter f a =
    let result = ref [] in
    let n = ref 0 in
        Array.iter
            (fun x ->
                if f x then begin
                    result := x :: !result;
                    incr n
                end)
            a;
    match !result with
    | []    ->    [| |]
    | x::xs    ->
        let filtered = Array.create !n x in
        let rec fill i = function
        | []    -> filtered
        | x::xs -> filtered.(i) <- x; fill (i+1) xs
        in
            fill 1 xs;;

On 11/25/05, Richard Jones < rich@xxxxxxxxxxx> wrote:

I've changed the implementation of Array.filter to use BitSets at your
suggestion.  The version using the actual BitSet type is quite a bit
shorter than your version.

I've also implemented Array.partition along the same lines.

Rich.

--
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
ocaml-lib-devel mailing list
ocaml-lib-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/ocaml-lib-devel


Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>