Some optimization results

Richard Harter rh at smds.UUCP
Sun May 5 08:55:58 AEST 1991


This is a followup.  The timings referred to were done in situ, i.e.
the routine being tested was executed as part of the execution of a
large program running a fixed test suite.  For the purposes of timing
this is not entirely happy because of the high variance of gprof timings.
To get better times, I set up a test bed program to time the loop itself.
All variables were register variables with the arrays and pointers being
ints.  Here are the loop times:

Statement			Unroll=1	Unroll=8

if (*ia++ != *ib++) break;	.58 ms		.48 ms
check += (*ia++ == *ib++);	.43 ms		.33 ms
check |= (*ia++ ^ *ib++);	.32 ms		.20 ms

These times are fairly repeatable.  Note that the time reduction due to
unrolling loops is constant.  This implies that loop unrolling only
provides signifigant improvements in relative times if the loop is very
tight.  Also not that loop unrolling past 8 times offers very little
advantage -- with a unroll factor of 8 you have already removed 7/8 of
the loop tests.
-- 
Richard Harter, Software Maintenance and Development Systems, Inc.
Net address: jjmhome!smds!rh Phone: 508-369-7398 
US Mail: SMDS Inc., PO Box 555, Concord MA 01742
This sentence no verb.  This sentence short.  This signature done.



More information about the Comp.lang.c mailing list