Show us your best programming optimazation tip !

@koedoe (100)
South Africa
January 16, 2007 1:05pm CST
I've been looking for a good source on general everyday programming optimazation tips. It can be in C++,Java and c#
1 response
@aiguy01 (588)
• United States
16 Jan 07
1. Turn you embedded SQL statements to stored procedure. 2. Use NOLOCK on SQL statements which do not update the database. 3. Use NOCOUNT on SQL statements if you do not need a row count returned. 4. Make sure your read/write caching is above 95% or add more memory. 5. Use SQL Server 2005 to take abvantage of 64 bit processing and more then 4GB of memory. 6. Avoid creatings strings dynamically in loops. Memory access is expensive. Build a string before you enter a loop and reuse the string for each iteration. 7. Use a code profiler to identify the top 10 cpu hogs in a program before optimizing to make sure you're optimizing the right routines.
@koedoe (100)
• South Africa
16 Jan 07
Hi looks good, But' I'm a bit confussed with no 6 ?
@aiguy01 (588)
• United States
16 Jan 07
We found a C# that was allocating a new string in a loop. Getting a value from an open SQL cursor. Inserting a string in a listbox Destroying the string and going to the next iteration. The loop was rewritten remove the creation and destruction of the string and just declaring a large enough string before we came into the loop to hold the maximum size string. Because the memory was only allocated and destroyed once instead of for each iteration, performance increased a couple orders of magnitude.