Unfortunate dynamic linking for everything

Dan Nelson dnelson at allantgroup.com
Tue Nov 18 12:46:40 PST 2003


In the last episode (Nov 18), M. Warner Losh said:
> In message: <200311181307.hAID7uHa032514 at dyson.jdyson.com>
>             dyson at iquest.net writes:
> : It really doesn't make sense to arbitrarily cut-off a discussion
> : especially when a decision might be incorrect.
> 
> I'd say that good technical discussion about why this is wrong would
> be good.  However, emotional ones should be left behind.  Except for
> John's message, most of the earlier messages have been more emotional
> than technical.
> 
> John, do you have any good set of benchmarks that people can run to
> illustrate your point?

Pretty much any benchmark that you can build statically and dynamically
should suffice.  I've attached a simple one that fills an array with
random numbers then qsorts them.  "make compare" will generate three
graphs at the end: time spent loading the executable, time spent within
the loops, and total time.  Note that both load and loop timings are
higher for the dynamic binary.  I ran it on a busy system, which is why
there are so many outliers.  Make sure you have
src/tools/tools/ministat installed someplace in your path.

Also see
http://lists.freebsd.org/pipermail/freebsd-current/2003-April/001106.html ,
where I had posted proc/pid/maps for a static and dynamic ls.

-- 
	Dan Nelson
	dnelson at allantgroup.com
-------------- next part --------------
all: compare

REPS=50

STATICLOGS=static.total.log static.loop.log static.load.log
DYNAMICLOGS=dynamic.total.log dynamic.loop.log dynamic.load.log
LOGS=${STATICLOGS} ${DYNAMICLOGS}

CFLAGS+=-Wall

static: svd.o
	${CC} -static ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} ${LDADD}

dynamic: svd.o
	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} ${LDADD}

clean:
	rm -f static dynamic ${LOGS} *.o

.PHONY: run
run ${LOGS}: static dynamic
	@rm -f ${LOGS}
	@reps=0; while [ $$reps -lt ${REPS} ] ; do  \
	  time -p ./static 2>&1 >> static.loop.log | sed -ne '/real/s/real //p' >> static.total.log ; \
	  time -p ./dynamic 2>&1 >> dynamic.loop.log | sed -ne '/real/s/real //p' >> dynamic.total.log ; \
	  echo -n . ; \
	  reps=$$(($$reps+1)) ; \
	done
	@echo
	@paste static.total.log static.loop.log | awk '{print $$1 - $$2}' > static.load.log
	@paste dynamic.total.log dynamic.loop.log | awk '{print $$1 - $$2}' > dynamic.load.log

compare: ${LOGS}
	ministat -s static.load.log dynamic.load.log 
	ministat -s static.loop.log dynamic.loop.log 
	ministat -s static.total.log dynamic.total.log 
-------------- next part --------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>

#define SIZE 1024000

int comp(const void *a, const void *b)
{
	return memcmp(a, b, sizeof(int));
}

int main(int argc, char *argv[])
{
	int numbers[SIZE];
	int i;
	struct timeval tv1, tv2;

	gettimeofday(&tv1, NULL);

	srand(5);
	for (i = 0; i < SIZE; i++)
	{
		numbers[i] = rand();
	}
	qsort(numbers, SIZE, sizeof(*numbers), comp);
	gettimeofday(&tv2, NULL);

	timersub(&tv2, &tv1, &tv1);
	printf("%ld.%06ld\n", tv1.tv_sec, tv1.tv_usec);

	return 0;
}
-------------- next part --------------
ministat -s static.load.log dynamic.load.log
x static.load.log
+ dynamic.load.log
+--------------------------------------------------------------------------+
|   xx   +                                                                 |
|   xx  ++                                                                 |
|   xx  ++                                                                 |
|  xxxx ++                                                                 |
|  xxxx ++                                                                 |
|  xxxx ++                                                                 |
|  xxxx ++                                                                 |
|  xxxx +++                                                                |
|  xxxxx+++                                                                |
|  xxxxx*++++                                                              |
|  xxxxx*+++++ +                                                           |
| xxxxx**+++++ +   ++                                                      |
| xxxxx**+++++ ++  ++ +                                                    |
| xxxx*****+++++++**+ ++                                                   |
| xxx******+*++++***+*++ ++    *      x  ++            +                  +|
||___M_A____|                                                              |
|   |______M__A_________|                                                  |
+--------------------------------------------------------------------------+
    N           Min           Max        Median           Avg        Stddev
x  96      0.001561      0.027646      0.003969  0.0049661042  0.0040137086
+  96      0.003765       0.05356       0.00824   0.010588323  0.0072195082
Difference at 95.0% confidence
        0.00562222 +/- 0.00165239
        113.212% +/- 33.2733%
        (Student's t, pooled s = 0.00584085)

ministat -s static.loop.log dynamic.loop.log
x static.loop.log
+ dynamic.loop.log
+--------------------------------------------------------------------------+
|               +                                                          |
|        x      +                                                          |
|        x      +                                                          |
|       xxx+    +                                                          |
|       xxx+    +    +                                                     |
|    xx xxx+   ++    +                                                     |
|    xx xxx+x  *+  + +                                                     |
|    xx xxx*x  **x + ++                                                    |
|    xx xxx*x +*** + ++   +                                                |
|  xxxx xx*** +***+++++  ++x                                               |
| xxxxxxx****++***+*+++++++x  +  +                                         |
|xxxxxxx*****+*******+**+*+x++++ + +    x       +  +         x  +     x+  *|
||________M__A___________|                                                 |
|        |________M__A__________|                                          |
+--------------------------------------------------------------------------+
    N           Min           Max        Median           Avg        Stddev
x  96      2.117437      2.946891      2.214953     2.2526589    0.13604786
+  96      2.196508      2.945064      2.305462     2.3386929    0.13174233
Difference at 95.0% confidence
        0.086034 +/- 0.037884
        3.81922% +/- 1.68175%
        (Student's t, pooled s = 0.133912)

ministat -s static.total.log dynamic.total.log
x static.total.log
+ dynamic.total.log
+--------------------------------------------------------------------------+
|        x      +                                                          |
|     x  x      ++                                                         |
|     x  x      ++                                                         |
|     x  x      ++                                                         |
|     x  x +    ++                                                         |
|     x  xx*    ++    +                                                    |
|     x xxx*   x+* + ++                                                    |
|    xx xxx*x +*** ++++  +                                                 |
|  xxxx x***x++***++++++ ++                                                |
| xxxxxxx*********+**+++ ++x  ++  +                                        |
|xxxxxxxx************+***+**++++  ++   x        +  +         x    +   *  +x|
||________M__A___________|                                                 |
|        |________M__A___________|                                         |
+--------------------------------------------------------------------------+
    N           Min           Max        Median           Avg        Stddev
x  96         2.119         2.961         2.218      2.257625    0.13686538
+  96         2.208         2.952         2.313     2.3492813    0.13316888
Difference at 95.0% confidence
        0.0916563 +/- 0.0382001
        4.05985% +/- 1.69205%
        (Student's t, pooled s = 0.13503)


More information about the freebsd-current mailing list