From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA21039; Fri, 4 May 2001 22:38:50 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA20998 for ; Fri, 4 May 2001 22:38:45 +0200 (MET DST) Received: from mta7.pltn13.pbi.net (mta7.pltn13.pbi.net [64.164.98.8]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f44Kcer14996; Fri, 4 May 2001 22:38:40 +0200 (MET DST) Received: from checkerlap.d6.com ([64.160.53.33]) by mta7.pltn13.pbi.net (Sun Internet Mail Server sims.3.5.2000.03.23.18.03.p10) with ESMTP id <0GCT003GEVH6S4@mta7.pltn13.pbi.net>; Fri, 4 May 2001 13:27:15 -0700 (PDT) Date: Fri, 04 May 2001 13:27:36 -0700 From: Chris Hecker Subject: Re: [Caml-list] printable digest strings In-reply-to: <20010504113727.A9728@pauillac.inria.fr> X-Sender: def6@shell16.ba.best.com To: Xavier Leroy , Miles Egan Cc: caml-list@inria.fr Message-id: <4.3.2.7.2.20010504125129.00e25990@shell16.ba.best.com> MIME-version: 1.0 X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Content-type: text/plain; charset="us-ascii" References: <20010503153234.A28259@caddr.com> <20010503153234.A28259@caddr.com> Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >Or in a more imperative style (real programmers don't build >intermediate lists :-) Real programmers prematurely optimize silly little functions (code below) and don't call sprintf per character: :) native code test secs ---- ---- hex 0.38 hexu 0.16 hexx 7.30 bytecode test secs ---- ---- hex 2.75 hexu 2.31 hexx 27.24 > string_map On a more serious note/question, you define string_map as: string_map : (char -> 'a) -> string -> 'a list Since I'm still trying to grok this functional thing, I guess there's really no other way to do it (except maybe 'a array) because the function could expand its char into another type, right? In other words, other maps are map: ('a -> 'b) -> 'a type -> 'b type so there's a certain amount of symmetry. Since string is a builtin, there's no way to have a "float string" or whatever if your function is char -> float. Is 'a array the right thing to return here, or 'a list? Or is this a stupid irrelevant question? Chris PS. It's pretty clear from looking at the asm output of hexu that languages with shifted-up ints sure could benefit from crazy shift-mask instructions like the PPC has. The x86 just dies on this sort of thing with no ternary instructions and no good shift-mask ops. --- test harness --- let _ = let s = String.make 10000 'g' in let r = ref "" in for i = 0 to 100 do r := hexstring s; done ---- hex ---- let hexstring s = let res = String.create (String.length s * 2) in let hex = "0123456789abcdef" in for i = 0 to String.length s - 1 do let c = Char.code s.[i] in res.[2*i] <- hex.[c lsr 4]; res.[2*i+1] <- hex.[c land 15] done; res ---- hexu ---- let hexstring s = let res = String.create (String.length s * 2) in let hex = "0123456789abcdef" in for i = 0 to String.length s - 1 do let c = Char.code (String.unsafe_get s i) in String.unsafe_set res (2*i) (String.unsafe_get hex (c lsr 4)); String.unsafe_set res (2*i+1) (String.unsafe_get hex (c land 15)); done; res ---- hexx ---- let hexstring s = let res = String.create (String.length s * 2) in for i = 0 to String.length s - 1 do String.blit (Printf.sprintf "%02x" (Char.code s.[i])) 0 res (2 * i) 2 done; res ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr