From: Amit D. <ami...@gm...> - 2005-11-25 12:40:41
|
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 calle= d by both find_all and filter, which returns list * length). -Amit (Code for skaller below) let filter f a =3D let result =3D ref [] in let n =3D ref 0 in Array.iter (fun x -> if f x then begin result :=3D x :: !result; incr n end) a; match !result with | [] -> [| |] | x::xs -> let filtered =3D Array.create !n x in let rec fill i =3D function | [] -> filtered | x::xs -> filtered.(i) <- x; fill (i+1) xs in fill 1 xs;; On 11/25/05, Richard Jones <ri...@an...> 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=3D7637&alloc_id=3D16865&op=3Dclick > _______________________________________________ > ocaml-lib-devel mailing list > oca...@li... > https://lists.sourceforge.net/lists/listinfo/ocaml-lib-devel > |