[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: mplayer



At Mon, 21 Jul 2003 10:41:52 +0200,
Giacomo A. Catenazzi wrote:
> 
> Samium Gromoff wrote:
> 
> > [ lots of discussion about function pointer slowdown ]
> > 
> > Matthias Urlichs wrote:
> > 
> >>If the function-pointerized code just looks ugly, the C preprocessor is
> >>your friend -- on the other hand you don't even need that, as foo(bar,...)
> >>is equivalent to (*foo)(bar,...) if foo is a pointer to a function.

[...]

> += i;

[...]

> -= i;
> Not += i;

 Indeed, the intended reason was to have a scale of difference involved.

> 

[...]

> > Probably i just was misled, probably gcc outsmarted me...
> 
> 
> You do a long loop, but not ouside fn() or a(), so you don't notice
> the single call.
> Put the loop outside the call.
> 
> ciao
> 	giacomo
> 
  Uhhuh, that was really lame of me 8)

  Here is the fixed version, and the results:
----------------( moo.c
int a(int p, int inc)
{
	return p + inc;
}

int b(int p, int inc)
{
	return p - inc;
}

int main(int argc, char **argv)
{
	int (*fn)(int parm, int inc);
	int sum = 0, i;

	if (argc < 2) {
		printf("parm count error: %d\n", argc);
		exit(-1);
	}

	switch (argv[1][0]) {
	case 'a':
		fn = a;
		for (i = 0; i < 100000000; i++)
			sum = fn(sum, i);
		printf("%d\n", sum);
		break;
	case 'b':
		fn = b;
		for (i = 0; i < 100000000; i++)
			sum = fn(sum, i);
		printf("%d\n", sum);
		break;
	case 'c':
		for (i = 0; i < 100000000; i++)
			sum = a(sum, i);
		printf("%d\n", sum);
		break;
	default:
		printf("parm value error\n");
		exit(-1);
	}

	return 0;
}

--------------( results (five runs, max/min thrown away):
	a:		b:		c:
real	0m2.597s	0m2.680s	0m2.530s
real	0m2.598s	0m2.680s	0m2.532s
real	0m2.598s	0m2.682s	0m2.532s

avgs:
a: 2.598
b: 2.680
c: 2.530


regards, Samium Gromoff



Reply to: