[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Swarm-Support] executable code on the stack (revisited)
From: |
Marcus G. Daniels |
Subject: |
Re: [Swarm-Support] executable code on the stack (revisited) |
Date: |
Thu, 04 Sep 2003 18:16:41 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.5b) Gecko/20030827 |
Russell Standish wrote:
One can do something very similar in C++ - methods are nested within
classes, and class instance variables are global to the group of
methods belonging to that class. There are no performance implications
in using a method over a standard global function call. Obviously the
same is possible in Objective C, however I'm not sure of the
performance implications, since Obj C uses dynamic binding of methods
to objects...
No inherent costs. Just the usual things, like ensuring that the things
you want are in registers.
For example, passing `i' as an argument can make the code faster because
it will get a register.
In the two cases below, `i' is in static memory or on the stack.
Dynamic binding is completely orthogonal as method implementation bodies
are essentially funtion calls with two extra arguments (the object and
selector). A nested function in a method implementation body is just
like a nested function in a C function as below.
(22.30 is the CPU time for the non-nested case and 21.96 is the CPU time
for the nested function.)
$ /packages/bin/gcc -O3 -static tt.m -o tt
$ ./tt
22.300000 499999999067108992.000000
21.960000 499999999067108992.000000
$ cat tt.m
#include <time.h>
#define COUNT 1000000000
clock_t s1, s2, s3;
unsigned ii;
double
test_outside ()
{
return (double) ii;
}
int
main (int argc, const char **argv)
{
clock_t s11, s12, s21, s22;
{
double sum = 0.0;
s11 = clock ();
for (ii = 0; ii < COUNT; ii++)
sum += test_outside (ii);
s12 = clock ();
printf ("%f %f\n", (double) (s12 - s11) / CLOCKS_PER_SEC, sum);
}
{
double sum = 0.0;
unsigned i;
double test_inside () { return (double) i; }
s21 = clock ();
for (i = 0; i < COUNT; i++)
sum += test_inside ();
s22 = clock ();
printf ("%f %f\n", (double) (s22 - s21) / CLOCKS_PER_SEC, sum);
}
}