From: Alex Rubinsteyn <alex.rubinsteyn@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] Overhead of first class modules
Date: Fri, 16 Sep 2011 16:08:55 -0400 [thread overview]
Message-ID: <CAMB58pGrrz1BLn59i_9eAAMb=Z7D+4dKuoOuydQVfkQ8ODfUFw@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 972 bytes --]
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.
[-- Attachment #2: Type: text/html, Size: 2436 bytes --]
next reply other threads:[~2011-09-16 20:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-16 20:08 Alex Rubinsteyn [this message]
2011-09-16 20:36 ` ygrek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMB58pGrrz1BLn59i_9eAAMb=Z7D+4dKuoOuydQVfkQ8ODfUFw@mail.gmail.com' \
--to=alex.rubinsteyn@gmail.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).