From: Richard J. <ri...@an...> - 2008-06-10 08:48:54
|
On Sun, Jun 08, 2008 at 09:39:39PM +0200, Florent Monnier wrote: > > In fact, thinking about this a bit more clearly, there's no need to > > set the tag at all if all you do is call 'String.unsafe_get', so this > > works: > > > > let hairy_string_of_float (d : float) = > > (Obj.magic d : string) > > > > Be really careful that you don't let the returned "string" escape into > > the wild though :-) It still looks like a double to the garbage > > collector and it's not a well-formed string either, so any function > > other than 'String.unsafe_get' is highly likely to fail. > > Hi, > this hairy version is as fast as the one with the external oneliner C, > here are the elapsed times (from Sys.time) for 3_000_000 floats written > to /dev/null: > > 0.51 sec. -- with extern oneliner C > 0.50 sec. -- the hairy one wins, well done! That's to be expected. Obj.magic is just the %identity compiler primitive, which the compiler optimizes away completely, so the only overhead is (maybe) the function call and (maybe) the boxing up of the float argument. Rich. -- Richard Jones Red Hat |