Take a look at the code below. More readable by far IMHO.
Casper Hornstrup wrote:
-----Original Message-----
From: ros-dev-bounces(a)reactos.com [mailto:ros-dev-bounces@reactos.com] On Behalf Of
Thomas
Weidenmueller
Sent: 28. september 2005 17:27
To: ReactOS Development List
Subject: Re: [ros-dev] Re:[ros-svn] [gdalsnes] 18113:-reorderInsertXscendingOrdermacro
argument
order and update uses
Casper Hornstrup wrote:
The alternative is: do the cleanup at every
return, use goto or use
try/finally.
1)Cleanup at every return is madness. Most functions in ros do a large
amount of cleanup at each return and I sometimes spot mistakes where
one/more return misses some cleanup. Those errors are _hard_ to find.
The functions are too large then. Use more smaller functions instead.
I agree with Nathan. Having tons of small functions often isn't a good
solution, especially when you'd have to create dozens of small helper
functions. That not just only generates slower code but also makes it
more difficult to get a picture of the algorithm used. I much more
prefer jumping to cleanup labels the way Nathan demonstrated it. Of
course I avoid it where it doesn't make sense.
- Thomas
There is practically no difference in execution speed.
Casper
------------------------------------------------------------------------
#include <stdio.h>
#include <windows.h>
#define NumberOfIterations 60000
void RunCollapsed()
{
int i, j;
for (i = 0; i < NumberOfIterations; i++)
{
for (j = 0; j < NumberOfIterations; j++)
{
}
}
}
static void Helper()
{
int j;
for (j = 0; j < NumberOfIterations; j++)
{
}
}
void RunNonCollapsed()
{
int i;
for (i = 0; i < NumberOfIterations; i++)
{
Helper();
}
}
void RunOnce(LARGE_INTEGER *collapsedTicks, LARGE_INTEGER *nonCollapsedTicks)
{
LARGE_INTEGER start;
LARGE_INTEGER stop;
QueryPerformanceCounter(&start);
RunCollapsed();
QueryPerformanceCounter(&stop);
collapsedTicks->QuadPart = stop.QuadPart - start.QuadPart;
printf("Collapsed: %lu ticks\n", collapsedTicks->QuadPart);
QueryPerformanceCounter(&start);
RunNonCollapsed();
QueryPerformanceCounter(&stop);
nonCollapsedTicks->QuadPart = stop.QuadPart - start.QuadPart;
printf("NonCollapsed: %lu ticks\n", nonCollapsedTicks->QuadPart);
printf("%d%%\n", (nonCollapsedTicks->QuadPart * 100) /
collapsedTicks->QuadPart);
}
int main()
{
LARGE_INTEGER collapsedTicks;
LARGE_INTEGER nonCollapsedTicks;
LARGE_INTEGER totalCollapsedTicks;
LARGE_INTEGER totalNonCollapsedTicks;
int i;
totalCollapsedTicks.QuadPart = 0;
totalNonCollapsedTicks.QuadPart = 0;
for (i = 0; i < 10; i++)
{
RunOnce(&collapsedTicks, &nonCollapsedTicks);
totalCollapsedTicks.QuadPart += collapsedTicks.QuadPart;
totalNonCollapsedTicks.QuadPart += nonCollapsedTicks.QuadPart;
}
printf("Average: %d%%\n", (totalNonCollapsedTicks.QuadPart * 100) /
totalCollapsedTicks.QuadPart);
}
------------------------------------------------------------------------
_______________________________________________
Ros-dev mailing list
Ros-dev(a)reactos.com
http://reactos.com:8080/mailman/listinfo/ros-dev