views:

135

answers:

6

One of biggest optimizations I've used is regard to this question:

http://stackoverflow.com/questions/1152414/import-from-text-file-to-sql-server-database-is-ado-net-too-slow

with the initialized version, insert each row per query use ADO.NET, I was able to insert about 100 rows/second. When I switched to batch insert, it rose to 1000 rows/second, and then, BulkCopy, I can get, about 7000 rows/second. All in same machine. 70 times better and even smaller, more-readable code.

So, what's the best optimization you've ever used to improve your code? Optimization means better tactic/strategy, not premature optimization :)

+3  A: 

Matrix multiplication by dividing it down to sub matrices small enough to fit inside the processor's cache.

Otávio Décio
wow neat! +1 from me
the_drow
A: 

I've done a few optimizations, and the pattern has always been to use a profiler, which gives you the bottlenecks, which tells you where to start working.

So, for instance I has a form updating live data. The screen was too slow. Profiler said > 10000 calls per minute to drawing function. So, I changed the strategy to simply save the data, and call draw() an acceptable amount. Result: Form isn't stuck, data looks like it's coming in.

Carlos
A: 

Using a Dictionary/Hashtable to look values up by key instead of using a foreach loop (especially for very long lists).

And a similar optimization: indexes on databases.

JohnB
And `TRUNCATE` instead of `DELETE` whenever possible!
JohnB
A: 

My brother claims the world record on this. By realigning some bit fields in a large Ada program so as not to cross word boundaries he sped up a routine by a factor of over 350,000.

EJP
A: 

I optimized the flexibility of our data model by using n-tier/repository loooooooooooong before it came into fashion. As a result, when a hurricane took out our in-house datacenter, we were able to take our backups and re-tool from in-house data servers to hosted SOAP webservers in less than 24 hours and requiring less than 1 page of code changes on the client apps.

markE
A: 

Recently, C++: replacing an CString-based "simple but slow" string parser with an alternate implementation using a pair of characterpointers as a "string segment".

Came down from 10 minutes to <10 seconds.

peterchen