I want to make fast iterations of a dynamically loaded library symbol. To see how much performance I can get comparing to hard-coding the function, I did some benchmarks for a simple addition operation.
I use this function to do the operation
long int func(long int x)
{
return x+1;
}
And this loops to test the time
Hard-coded: for(i=0;i
With the function (defined in the same file where the loop is):
for(i=0;i<N;i++)
c = func(c);
With func from a linked object (func.o):
for(i=0;i<N;i++)
c = object_func(c);
With func from a dynamically loaded symbol ( using dlopen and dlsym )
for(i=0;i<N;i++)
c = dynamic_func(c);
This are the results for different N values, and everything compiled with g++ -Ofast:
There are a couple of ''mysterious'' things, first the function version give some 0 time values so there are missing points in its line. Then, is almost an order of magnitude less than the hard-coded version. I presume that the compiler is optimizing the operation, so the times don't rise. Other strange thing is that for small N values the object or shared libraries give better times.
Anyone can explain this behavior? Is there a way to get better results for object or dynamic libraries for large N?
Thanks
Aucun commentaire:
Enregistrer un commentaire