From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p8GKCPXv019226 for ; Fri, 16 Sep 2011 22:12:25 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjYCALOsc05KfVI0kGdsb2JhbABBmSWHEgGHIAgUAQEBAQkJDQcUBCGBbAITGQEbHgMSCQddAREBBQFXnEeCWAqLQYJahSo7iG0CAwaGcgSCVJB2jQE9hAo X-IronPort-AV: E=Sophos;i="4.68,395,1312149600"; d="scan'208";a="109383944" Received: from mail-ww0-f52.google.com ([74.125.82.52]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 16 Sep 2011 22:12:19 +0200 Received: by mail-ww0-f52.google.com with SMTP id 40so6245413wwj.9 for ; Fri, 16 Sep 2011 13:12:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; bh=yNY2UWoX9nMLO6bAVwJbewM4UW8n7afRdcN/bpzgoZ0=; b=TUM2ByTWSuqAqD+9XUrkkxobgg9v62VRntTPB6wpMW1aHJBURpdsZVfLIXtaLcg97m mYj8Wj8VLKrbOped85+E/cZZ+2dixBsnz7AGblh/ATLTlQqkwKBtyyn6D70kA+bH0QGr Wy/j07UfdJTK4tNZTSBSPhETSXX6PgoLhl4xc= Received: by 10.227.203.137 with SMTP id fi9mr97817wbb.86.1316203765100; Fri, 16 Sep 2011 13:09:25 -0700 (PDT) MIME-Version: 1.0 Received: by 10.180.86.198 with HTTP; Fri, 16 Sep 2011 13:08:55 -0700 (PDT) From: Alex Rubinsteyn Date: Fri, 16 Sep 2011 16:08:55 -0400 Message-ID: To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=00151758b4cedef12a04ad14918d Subject: [Caml-list] Overhead of first class modules --00151758b4cedef12a04ad14918d Content-Type: text/plain; charset=ISO-8859-1 I ran a very simple experiment gauging the overhead of OCaml's new first-class modules. *direct.ml: * let f x = x + 1 let _ = let acc = ref 0 in for i = 0 to 10000000 do acc := !acc + (f 1) done *first_class_module.ml* module type S = sig val f : int -> int end module M = struct let f x = x + 1 end let package = (module M : S) let _ = let acc = ref 0 in for i = 0 to 10000000 do let module Local = (val package : S) in acc := !acc + (Local.f 1) done obj.ml let o = object method f x = x + 1 end let _ = let acc = ref 0 in for i = 0 to 10000000 do acc := !acc + o#f 1 done # ocamlopt direct.ml -o direct # ocamlopt first_class_module.ml -o first_class_module # ocamlopt obj.ml -o obj # time ./direct real 0m0.008s user 0m0.010s # time ./first_class_module real 0m0.012s user 0m0.020s # time ./obj real 0m0.058s user 0m0.060s So, the overhead of first class modules is slight, especially when compared with method invocation. --00151758b4cedef12a04ad14918d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I ran a very simple experiment gauging the overhead of OCaml's new firs= t-class modules.=A0

= direct.ml:=A0
let f x =3D x + 1
let _ =3D<= /div>
=A0 let acc =3D ref 0 in
=A0 for i =3D 0 to 10000000 do
=A0 =A0 acc :=3D !acc + (f 1)
=A0 done

module type S =3D sig val f : int -> int end
module M =3D= struct let f x =3D x + 1 end
let package =3D (module M : S)
let _ =3D
=A0 let acc =3D ref 0 in
=A0 for i =3D = 0 to 10000000 do
=A0 =A0 =A0let module Local =3D (val package : S) in
=A0 =A0= =A0acc :=3D !acc + (Local.f 1)
=A0 done

let o =3D object method f x =3D x + 1 end
let _ =3D
=A0 let acc =3D ref 0 in
=A0 for i =3D 0 to 10000000 do
=A0 =A0 =A0acc :=3D !acc + o#f 1
=A0 done


=
# ocamlopt direct.ml -o direct
# ocamlopt first_cl= ass_module.ml -o first_class_module
# ocamlopt obj.ml -o obj

<= /div>
# time ./direct
real 0m0.008s
user 0m0.010s

# time ./first_class_module
<= div>real 0m= 0.012s
user 0m0.020s

# time ./obj
real 0m0.058s
user 0m0.060s

So, the overhead of first class modul= es is slight, especially when compared with method invocation.=A0

--00151758b4cedef12a04ad14918d--