costs of procedure calls in smlc
Stephen Weeks
sweeks@research.nj.nec.com
Sun, 28 Feb 1999 21:53:39 -0500
Here are the times for making 200,000,000 nontail one argument
procedure calls (and returns) on eponym, in 4 different ways. The
first two are in smlc, one using intra-chunk calls, and the other
using inter-chunk calls. The third way is in NJ, and the fourth is
using C. All the code follows the timings. As you can see, procedure
calls cost big time in smlc relative to NJ. And as I recall, most
calls are interchunk, so they cost even more.
time(s)
smlc intra-chunk 50.71
smlc inter-chunk 79.54
NJ 25.38
C 56.27
--------------------------------------------------------------------------------
(* smlc intra-chunk and NJ *)
val rec deep =
fn 0 => 1
| n => 1 + deep(n - 1)
val _ =
let
val rec loop =
fn 0 => ()
| n => (deep 100000; loop(n - 1))
in loop 2000
end
--------------------------------------------------------------------------------
(* smlc inter-chunk *)
val rec deep =
fn 0 => 1
| n => 1 + deep'(n - 1)
and deep' =
fn 0 => 1
| n => 1 + deep(n - 1)
val _ =
let
val rec loop =
fn 0 => ()
| n => (deep 100000; deep' 100000; loop(n - 1))
in loop 1000
end
--------------------------------------------------------------------------------
/* C code */
int deep(int n) {
if (0 == n)
return 1;
else return (1 + deep(n -1));
}
int main() {
int i;
for (i = 0; i < 2000; ++i)
deep(100000);
}
--------------------------------------------------------------------------------