The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Good programmers don't write slow code?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Good programmers don't write slow code? Posted: Oct 2, 2003 10:13 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Good programmers don't write slow code?
Feed Title: David Buck - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/buck-rss.xml
Feed Description: Smalltalk can do that
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From David Buck - Blog

Advertisement
I've heard it said that "good programmers don't write slow code". Well, I hate to say it, but this is outright wrong. There is normally a tradeoff between code simplicity and speed. My strategy is normally to make the code simple first so I can get it running. Once it runs, use the performance profiler to determine what's slow and optimize that part hopefully with better algorithms.

I was working on one project in Smalltalk/V for an insurance company. They were calculating illustrations of insurance policies over 20 years or more. We used a model similar to a spreadsheet except that each column had a formula instead of each cell.

At one point, the customer said that they wanted to solve for a value in the last row by changing another value in the first row. We used the bisection method to narrow down the answer because it was the easiest algorithm to implement and get the answer.

This technique worked well for a while but when they tried it on a more complex policy, it started taking over several minutes to calculate. They started to panic and assigned someone to look into rewriting the code in C to get performance.

I told them that re-writing it in C might give them a performance improvement of 5 times or so (for heavy floating point calculations). Let's see what we can do with Smalltalk first. We could use a better algorithm than bisection to find the zero of functions. Rikker's method would give us about 5 times improvement. Then we could calculate only the columns that contribute to the answer while we are solving. That gives an additional 3 times. Then there were some columns that only had an effect for a range of rows and would calculate to 0 otherwise. Eliminating these calculations would give us another 2 times improvement. The total improvement was 30 times which would far exceed the benefit of re-writing it in C.

Using slow algorithms is often the easiest way to get things running. Once it runs, determine if it's too slow then improve performance as needed. If you can, make high level optimizations rather than low level ones - if you can run something slow less often, it's usually better than making the slow thing faster.

Read: Good programmers don't write slow code?

Topic: hard to spot bugs Previous Topic   Next Topic Topic: The soft in software

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use