??? 03/16/05 09:28 Read: times |
#89764 - If you need to be optimum - don't use C Responding to: ???'s previous message |
For years I crafted highly optimised asm code for many processors - I sweat blood on some jobs. I was told that the 'c' compilers would equal the best handcrafted assembler so I had to try it out. The reality is I can beat the compiler hands down for both speed and code density. Then I read 'Code Complete' which opened my eyes to the issues of 'optimisation'. I now write most of my code in 'c' and not worry too much about optimisation unless certain sections of code are proven to have a speed issue. Assembler is my last choice. Algorithmic optimisation generally gives the best results - recently I looked at two methods of CRC generation/checking for MODBUS. I had always used the looped method as it used the least code - it was dog slow- one a test packet it was taking around 65mS (including overhead). Changing to a table driven method drove the time down to 15mS - at the expense of code space (which I had plenty of). Had I just coded the looped code in assembler it would have been faster - but probably not as fast as the table driven code. Also, I could've coded the table driven code in assembler and got it a little faster - not 50mS faster though! So, if you'r prepared to sacrifice a bit of outright performance and code size, 'c' is just fine. I write more code ,faster and with less bugs - that's what my customers want. If you need more code space, just buy a bigger micro - which isn't much of a burden these days. Once you get over the mental objection and start writing code - it all gets forgotten for the most part. The magic compiler does its job and we're happy! It's a bit like never looking into the kitchen of your favourite restaurant - you might not like what you see! But the food tastes good. |