From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 8D4A4BBAF for ; Mon, 23 Aug 2010 14:14:20 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhwBAOYCckzRVdU0kGdsb2JhbACgKAgVAQEBAQkJDAcRAx+eMYkYghOFdS6IVAEBAwWFMgSJdopF X-IronPort-AV: E=Sophos;i="4.56,257,1280700000"; d="scan'208";a="68104455" Received: from mail-yw0-f52.google.com ([209.85.213.52]) by mail4-smtp-sop.national.inria.fr with ESMTP; 23 Aug 2010 14:14:20 +0200 Received: by ywo32 with SMTP id 32so445280ywo.39 for ; Mon, 23 Aug 2010 05:14:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=4X/OqG3dpDvUVzAjXFTS3+lgoj07Jm5f+JnhsWnTXvg=; b=a6fzoZdz5ok/DO5zkvoWJKzkNXSeMKTFQTF0whNAh2oNjbmN7raPwaqdPsmgcoqXi2 fYGaO3iriNjQjrWbE5X1wzymInVmXDx0fp879aJAwJJHIBi1wY5lAFfRA+FEtWDUNv1I nNw2eJZ1aJCy6t8eN9+61gNZ/Hr08SQ891h04= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=QlChfjUpeU4yCjGQs4JnPCJLmwCxWFJazGGYmhG7syfDmxPNaLcJ/RCbV4q27sT8aH PvoD+IP0Q5WN9JW1VE1y7jm+gP7fbmU1KdCLfXfcESlAYizsb+/+y82w3nI27dnUXIaM lb5quCK8RTnziqSCf+kzCVxEYGn/it1p3dHAw= MIME-Version: 1.0 Received: by 10.90.70.20 with SMTP id s20mr3313423aga.41.1282565657357; Mon, 23 Aug 2010 05:14:17 -0700 (PDT) Received: by 10.220.87.162 with HTTP; Mon, 23 Aug 2010 05:14:16 -0700 (PDT) In-Reply-To: <20100823.140626.634675953541672216.Christophe.Troestler+ocaml@umons.ac.be> References: <20100823.140626.634675953541672216.Christophe.Troestler+ocaml@umons.ac.be> Date: Mon, 23 Aug 2010 08:14:16 -0400 Message-ID: Subject: Re: [Caml-list] Question about float refs. From: Ethan Burns To: Christophe TROESTLER Cc: caml-list@yquem.inria.fr, ruml@cs.unh.edu Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; christophe:01 troestler:01 christophe:01 troestler:01 ocaml:01 printf:01 printf:01 unboxed:01 allocating:01 burns:98 burns:98 23,:98 wrote:01 wrote:01 rewrite:01 On Mon, Aug 23, 2010 at 8:06 AM, Christophe TROESTLER wrote: > On Thu, 19 Aug 2010 07:52:33 -0400, Ethan Burns wrote: >> >> let r =3D ref 0.0 ;; >> for i =3D 0 to 1000000000 do r :=3D float i done; >> Printf.printf "%f\n" !r; >> Printf.printf "words: %f\n" (Gc.stat ()).Gc.minor_words > > To add a precision to others' answers : float refs are unboxed > _locally_. =A0If you rewrite your code as > > let r =3D ref 0.0 in > for i =3D 0 to 1000_000_000 do r :=3D float i done; > Printf.printf "%f\n" !r; > Printf.printf "words: %f\n" (Gc.stat ()).Gc.minor_words > > then it runs at about the same speed as you other version. $ time ./a.out 1000000000.000000 words: 2000000367.000000 real 0m2.655s It does seem to run a lot faster than my first version, but it also seems to allocate a whole lot. If it is still allocating just as much why is this version so much faster? Ethan